I have an FirebaseMessagingService class for Firebase:
public class FcmMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String message = remoteMessage.getNotification().getBody();
Map<String, String> params = remoteMessage.getData();
Bitmap remote_picture = null;
remote_picture = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.logo);
intent = new Intent(this, HomeDrawer.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("Notification Title");
notificationBuilder.setContentText(message);
notificationBuilder.setSmallIcon(R.drawable.ic_notif);
notificationBuilder.setLargeIcon(remote_picture);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new Notification();
noti = notificationBuilder.build();
//notificationBuilder.setVibrate(new long[] { 1000, 1000});
//notificationBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notificationManager.notify(0,noti);
super.onMessageReceived(remoteMessage);
}
If the application is in background, (not actively open, but in the background, not closed) the notification smallIcon and LargeIcon doesn't appear, the default ones for android appears instead, also if I changed
intent = new Intent(this, HomeDrawer.class);
to any other activity class, it doesn't open the class I specified and opens the last class I left open in the background.
What am I doing wrong? SmallIcon and LargeIcon are not working properly if the background. However, notification message appears fine and also remoteMessage.getData(); gets the data correctly, it's all about the behavior of icons and intent class.
Thanks in advance.