You can handle all push events from all difference services (with Firebase). First create YouUniversalFCM extends WakefulBroadcastReceiver
For instance:
public class YourUniversalFCM extends WakefulBroadcastReceiver { private static final String ACTION_REGISTRATION = "com.google.android.c2dm.intent.REGISTRATION"; private static final String ACTION_RECEIVE = "com.google.android.c2dm.intent.RECEIVE"; @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); for (String key : intent.getExtras().keySet()) { Log.d( "TAG", "{UniversalFCM}->onReceive: key->" + key + ", value->" + intent.getExtras().get(key) ); } switch (action) { case ACTION_REGISTRATION:
Next in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <application ...> ... <receiver android:name=".fcm.receivers.UniversalFCM" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.google.android.c2dm.intent.REGISTRATION"/> <category android:name="YOUR_PACKAGE"/> </intent-filter> </receiver> </application>
Replace YOUR_PACKAGE with your application package. All this. If you want to subscribe to another push service, you must add YourTokenService
public class YourTokenService extends FirebaseInstanceIdService { @Override public void onTokenRefresh() { String refreshedToken = FirebaseInstanceId.getInstance().getToken(); Ld(TokenService.class, "onTokenRefresh() Refreshed token: " + refreshedToken);
And declared in AndroidManifest.xml
<service android:name="YourTokenService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service>
source share