How to resolve conflicts when integrating Firebase Cloud Message simultaneously?
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:
-
Create and statically register a BroadcastReceiver in your application:
- Create a BroadcastReceiver, for example
YourCustomBroadcastReceiver.java. - Register it to the
applicationnode of your application'sManifest.xmlfile 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> - Create a BroadcastReceiver, for example
-
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.
-
Listen to and handle related events: You need to migrate the logic from
MyFirebaseMessagingServicetoYourCustomBroadcastReceiver. 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.
