Skip to content

Push notification improvements

Compare
Choose a tag to compare
@patedit patedit released this 07 Mar 22:14
· 501 commits to master since this release

Fixes

  • Use LruCache from android.util and remove any dependencies with supportv4 library
  • Push token was not set-up correctly if a user was not identified

Improvements

Allow sub-classes to override push notifications payload

public class CustomMixpanelFirebaseMessaging extends MixpanelFCMMessagingService {
    @Override
    protected void onMessageReceived(Context context, Intent intent) {
        if (intent.getExtras().containsKey("mp_message")) {
            intent.putExtra("mp_message", "CUSTOM MESSAGE");
        }
        super.onMessageReceived(context, intent);
    }
}

Support when more than one push provider is used

Android doesn't allow an app to have more than one handler for com.google.firebase.MESSAGING_EVENT intent filter action. Only the first registered service will handle a firebase message. If you need to use multiple push providers, you can now easily access Mixpanel FCM handler from your custom class. Register your custom FirebaseMessagingService service and:

public class PushProvidersHandler extends FirebaseMessagingService {
    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
        MixpanelFCMMessagingService.addToken(s);

        // Do something else with other providers here
        ....
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        if (remoteMessage.getData().containsKey("mp_message")) {
            MixpanelFCMMessagingService.showPushNotification(getApplicationContext(), remoteMessage.toIntent());
        }
        // Do something else with other providers here
        ....
    }
}