I am Using FCM in my app. I can get the messages when my app is in foreground or background and I can also navigate to whatever page I want, but when I want to send some extra parameters to that activity, they are not reflecting and neither is the debug not firing in my activity after tapping the notification. I need to pass the extra values to my activity. Please help. The code is below:
My Listener class is
public class MyFcmListenerService extends FirebaseMessagingService {
// @Override
/*public void onMessageReceived(RemoteMessage message){
String from = message.getFrom();
Map data = message.getData();
}*/
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map data = remoteMessage.getData();
Object Oppname= ((ArrayMap) data).valueAt(1);
Object moduleid= ((ArrayMap) data).valueAt(0);
sendNotification(Oppname.toString(),moduleid.toString());
}
//This method is only generating push notification
//It is same as we did in earlier posts
private void sendNotification(String messageBody,String Moduleid) {
Intent intent = new Intent(this, QuizActivity.class);
String Category="";
switch (Moduleid) {
case "33":
Category = "Category";
break;
case "34":
Category = "sales";
break;
case "36":
Category = "jobs";
break;
case "37":
Category = "professional";
break;
case "38":
Category = "sports";
break;
case "39":
Category = "meetings";
break;
case "40":
Category = "travel";
break;
case "41":
Category = "realestate";
break;
case "42":
Category = "banking";
break;
case "43":
Category = "health";
break;
}
intent.putExtra("Category",Category);
intent.putExtra("PushType","");
intent.putExtra("oppId","");
intent.putExtra("chkboxType","chkboxlive");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Right Place Right Time")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}