While Using Firebase push notification there are two cases to handle data payload( e.g. your Activity name etc.).
case 1: When your app is running in foreground(currently running on screen) you would get data payload from RemoteMessage object
in onMessageReceived(RemoteMessage remoteMessage)
method that you have overridden in your class that must extend FirebaseMessagingService
class.
For example :
public class FirebaseMessagingServiceHelper extends FirebaseMessagingService {
private final String TAG = "FirebaseMsgServiceHelper";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> dataPayload = null;
dataPayload = remoteMessage.getData();
}
}
case 2: When your app is running in background you would get data payload as extras in intent in your app's launcher Activity
.
For Example :-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get notification data info
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
//bundle must contain all info sent in "data" field of the notification
}
}
But these two cases were not working properly when I got name of the Activity
that is supposed to be open when user clicks on a notification on Notification Drawer
in click_action
and data payload in data
.
But when I putted down everything in data it worked fine for me in both the cases i.e.
whether app is running in foreground or in background your app would receive data payload everytime in RemoteMessage object
in onMessageReceived(RemoteMessage remoteMessage)
method.
Below is the link I link from where I got idea.
Firebase FCM notifications click_action payload