У меня есть класс FirebaseMessagingService для Firebase: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);
в любой другой класс деятельности, он не открывает класс I, указанный и открывают последний класс I остается открытым в фоновом режиме.
Что я делаю неправильно? SmallIcon и LargeIcon работают неправильно, если фон. Однако сообщение с уведомлением отображается отлично, а также remoteMessage.getData(); правильно получает данные, это все о поведении значков и класса намерений.
Заранее спасибо.
См http://stackoverflow.com/questions/37809885/firebase-push-notifications-update-db/37843845#37843845 –
см https: //stackoverflow.com/a/44800598/7329597 он доступен. Вы можете найти решение и надеяться, что получите ответ. –