C'est la façon dont j'ai abordé la question.
public class AppFCMService extends FirebaseMessagingService {
private final static String TAG = "FCM Message";
String notify, requstId, Notification;
PendingIntent pendingIntent;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
//split string and getting order id from notification
String Str = remoteMessage.getNotification().getBody();
String[] tmp;
tmp = Str.split(" ");
String temp1 = tmp[0];
String temp2 = tmp[1];
String id = tmp[2];
notify = temp1 + " " + temp2;
requstId = id;
showNotification(remoteMessage.getNotification().getBody());
}
private void showNotification(String messageBody) {
// check whether session has been initiated or not
if (new SessionHelper(getApplicationContext()).isLoggedIn()) {
if (notify.equalsIgnoreCase("Travel request")) {
Intent intent = new Intent(this, ViewTravelDetailsActivity.class);
intent.putExtra("TravelRequestID", requstId);
intent.putExtra("BackPress", "Notify");
pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
} else if (notify.equalsIgnoreCase("Timesheet replied")) {
Intent intent = new Intent(this, ViewReplyActivity.class);
intent.putExtra("timesheetActivityID", requstId);
intent.putExtra("BackPress", "Notify");
intent.putExtra("RealmData", "DeleteRealm");
intent.putExtra("isToday", "true");
pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
} else {
Intent intent = new Intent(this, Dashboard.class);
intent.putExtra("timesheetActivityID", requstId);
pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
}
} else {
Intent intent = new Intent(this, LoginActivity.class);
intent.putExtra("timesheetActivityID", requstId);
pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
}
Bitmap notifyImage = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(notifyImage)
.setColor(Color.parseColor("#FFE74C3C"))
.setContentTitle("TEST")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}