I was interested in how to detect if my application was opened from push notification created by the Android system.
Because some push notifications are created by our implementation of FirebaseMessagingService, others are auto-created by the system. If at the first case at the moment of opening the app from push notification - everything is clear, we can detect it by extras at the intent, that we put in the FirebaseMessagingService, at the second case I had some troubles because this intent was created by the system.
I`ve tried the second method from this article https://www.quora.com/How-is-it-possible-to-track-whether-an-application-was-opened-by-clicking-on-a-Push-Notification-Android#:~:text=Android but failed.
Nevertheless i noticed in intents extra "from" wasn`t putted value "notification", but there was my gcm_defaultSenderId I track it by this way :
Bundle intentExtras = getIntent().getExtras();
if (intentExtras != null && !intentExtras.isEmpty()) {
String intentSource = intentExtras.getString("from", "none");
if (intentSource.equalsIgnoreCase(getString(R.string.gcm_defaultSenderId))) {
trackAppOpenedFromPush();
}
}
It works properly but I`m not sure is it good practice. Does anyone have some thoughts?