Fcm Notification With Payload In Device's System Tray Not Getting Passed To App
Solution 1:
What are you using in MainActivity, if you are sending the notification and the app is in foreground, then it will take you to that very specific page. But if your app is background, then clicking on the notification tray will just launch your app. Here, if you want that on clicking the notification it shouldd lead you to a particular page then you have to use this piece of Code in your MainActivity.
if (getIntent().getExtras() != null) {
Intent intent = new Intent(MainActivity.this, NotificationActivity.class);
startActivity(intent);
}
Solution 2:
Check if your launcher activity has android:launchMode="singleTop" in the manifest and you are trying to read the extras in the onCreate() method.
If that is your case, only 1 instance of that class will be created, so if the activity is in the background when the user touches a notification in the tray, the method that is called is onNewIntent(). In that method you can get the extras and put them in the general intent this way:
@Override
public void onNewIntent(Intent intent){
super.onNewIntent(intent);
setIntent(intent);
}
and then onResume() you can access the extras with getIntent().getExtras() .
Happy coding!
Solution 3:
You will get all the data as a bundle in your launcher activity when your app is in background. To get those values, Make Sure to override onNewIntent in the launcher activity. In my case, it was the splash screen.
@OverrideprotectedvoidonNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getExtras() != null) {
for (String key : intent.getExtras().keySet()) {
Object value = intent.getExtras().get(key);
Log.d("data ", "Key: " + key + " Value: " + value);
}
}
}
Post a Comment for "Fcm Notification With Payload In Device's System Tray Not Getting Passed To App"