У меня есть класс FirebaseMessagingService для 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);
}
Если приложение находится в фоновом режиме (не активно открыто, но в фоновом режиме, не закрыто), уведомления smallIcon и LargeIcon не появляются, вместо них появляются стандартные для Android, также если я изменил
intent = new Intent(this, HomeDrawer.class);
к любому другому классу активности, он не открывает указанный класс и открывает последний класс, который я оставил открытым в фоновом режиме.
Что я делаю не так? SmallIcon и LargeIcon не работают должным образом, если фон. Однако сообщение уведомления отображается нормально, а также remoteMessage.getData(); получает данные правильно, все дело в поведении иконок и классе намерений.
Заранее спасибо.