【发布时间】:2017-02-03 00:36:29
【问题描述】:
我有一个 Firebase 的 FirebaseMessagingService 类:
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();正确获取数据,都是关于图标和意图类的行为。
提前致谢。
【问题讨论】:
-
见stackoverflow.com/a/44800598/7329597它是可用的。你可以找到解决方案,希望你能得到答案。
标签: android firebase firebase-cloud-messaging firebase-notifications