I am using FCM for push notification and i am sending data from Notification to the activity which i am opening.
Code for building Notification:
private void handleNotification(RemoteMessage remoteMessage) {
String notTitle = remoteMessage.getNotification().getTitle();
String notBody = remoteMessage.getNotification().getBody();
Intent resultIntent = new Intent(this, HomeActivity.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
resultIntent.putExtra("pushNotClick", "yes");
resultIntent.putExtra("pushNotHead", ""+notTitle);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.fb_icon);
mBuilder.setColor(getResources().getColor(R.color.colorPrimary));
mBuilder.setContentTitle(notBody)
.setContentText(notTitle)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
notificationChannel.enableLights(true);
assert mNotificationManager != null;
mBuilder.setSmallIcon(R.mipmap.icon_not);
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
mNotificationManager.createNotificationChannel(notificationChannel);
}
assert mNotificationManager != null;
mNotificationManager.notify((int) System.currentTimeMillis() /* Request Code */, mBuilder.build());
}
And i am getting the intent extras in my activity like this:
String notState = getIntent().getStringExtra("pushNotClick");
String notHead = getIntent().getStringExtra("pushNotHead");
But the problem is, everytime the Intent Extras are null in the Activity, i have checked all the possible reasons i found here in the community, but everytime the response is same.
I have tried below mentioned links
Android Notification PendingIntent Extras null
Always getting data null from notification intent android
I am not sure where i am doing wrong.