I implemented Firebase and testing the Firebase notifications. When the app is in the foreground I don\'t have problems, I implemented a service that extends FirebaseMes
I have used handleIntent(Intent intent) method to handle intent and move to that particular screen.
Below is my code which is working perfectly even when the app is in background :
FCMMessagingService.java which extends FCMMessagingService
@Override
public void handleIntent(Intent intent) {
super.handleIntent(intent);
Intent i = null;
String value_action = "";
if (intent.getExtras() != null) {
if (key.equals("click_action")) {
value_action = intent.getExtras().getString(key);
}
i = new Intent(FCMMessagingService.this, MainActivity.class);
i.putExtra("notificationFlag", value_action);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, notifCount, i, PendingIntent.FLAG_ONE_SHOT);
final int icon = R.mipmap.logo;
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
Notification notification;
notification = notificationBuilder.setSmallIcon(icon).setTicker(title)
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(body)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setSmallIcon(R.mipmap.notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), icon))
.build();
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(body);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), icon));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setSmallIcon(R.mipmap.logo);
} else {
notificationBuilder.setSmallIcon(R.mipmap.logo);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notifCount, notification);
}