logo
On this page

How to resolve conflicts when integrating Firebase Cloud Message simultaneously?

2024-05-11
Products / Plugins:Call Kit
Platform / Framework:Android

When Call Kit receives a message from FCM, if the message is not from ZEGO SDK, it will send a broadcast to the current application with the action com.zegocloud.zegouikit.call.fcm. The sample code is as follows:

Intent intent = new Intent("com.zegocloud.zegouikit.call.fcm");
intent.putExtra("remoteMessage", remoteMessage);
context.sendBroadcast(intent);

Therefore, if you have already integrated Firebase Messaging, simply follow these steps to complete the migration:

  1. Create and statically register a BroadcastReceiver in your application:

    • Create a BroadcastReceiver, for example YourCustomBroadcastReceiver.java.
    • Register it to the application node of your application's Manifest.xml file and set the action to "com.zegocloud.zegouikit.call.fcm". The example is as follows:
    <receiver
         android:name="com.zegocloud.uikit.demo.calloffline.YourCustomBroadcastReceiver"
         android:enabled="true"
         android:exported="false">
         <intent-filter>
           <action android:name="com.zegocloud.zegouikit.call.fcm"/>
         </intent-filter>
     </receiver>
  2. Remove the original FCM Service from Manifest.xml. The example is as follows:

    <service
        android:name=".java.MyFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    Please remove it to avoid conflicts with Zego SDK.

  3. Listen to and handle related events: You need to migrate the logic from MyFirebaseMessagingService to YourCustomBroadcastReceiver. The example is as follows.

    Original code:

    public class YourFirebaseMsgService extends FirebaseMessagingService {
         @Override
         public void onMessageReceived(RemoteMessage remoteMessage) {
             // Your custom logic
         }
     }

    Please migrate as follows and delete YourFirebaseMsgService.java:

    public class YourCustomBroadcastReceiver extends BroadcastReceiver {
    
         private static final String TAG = "CustomReceiver";
    
         public void onReceive(Context context, Intent intent) {
             com.google.firebase.messaging.RemoteMessage remoteMessage = intent.getParcelableExtra("remoteMessage");
             // Your custom logic
             Log.d(TAG, "onReceive.remoteMessage.getData: " + remoteMessage.getData());
         }
     }

By following these steps, you should be able to receive and handle your own FCM messages.

Previous

When publishing a stream, after calling the "enableTrafficControl" method to enable traffic control, why does only the main stream trigger the traffic control policy when the network quality is poor?

Next

When using the "muteMicrophone" and "enableAudioCaptureDevice" interfaces and setting the parameter to false, what is the difference between them?