I'm trying to create an notification to launch an Activity with extra information. However, currently it is not working.
Here is the code for creating the notification
private void showNotification(RemoteMessage remoteMessage){
try{
// Create an explicit intent for an Activity in your app
Intent i = new Intent(getBaseContext(), MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.putExtra(EXTRA_MESSAGE,remoteMessage);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_action_name)
.setContentTitle("Title")
.setContentText("Content")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setAutoCancel(true)
// Set the intent that will fire when the user taps the notification
.setFullScreenIntent(pendingIntent, true);
// notificationId is a unique int for each notification that you must define
notificationId++;
//https://developer.android.com/training/notify-user/time-sensitive
// Provide a unique integer for the "notificationId" of each notification.
startForeground(notificationId, builder.build());
}catch (Exception e){
Log.d(TAG, e.getMessage());
}
}
The Activity is launching after clicking the notification. However, inside the onCreate of the Activity when checking for the extra in the bundle it doesn't find it:
EDIT: Actually what I want is for the activity to show without the user having to click anything hence why I am using setFullScreenIntent.
if(bundle!=null && bundle.containsKey(CustomFirebaseMessagingService.EXTRA_MESSAGE)){
Log.d(TAG, "MainActivity has extra message");
}else{
Log.d(TAG, "MainActivity doesn't have extra message");
}
My logs say MainActivity doesn't have extra message