【发布时间】:2018-02-15 04:56:40
【问题描述】:
我正在使用 firebase 消息服务收到通知。一切正常,但我面临的一个问题是单击通知时我无法打开通知详细信息活动。虽然调试它工作正常,但在发布版本中,我无法找到错误。
这是我的代码:
Log.d(TAG, "From: " + remoteMessage.getFrom());
NewsId = remoteMessage.getNotification().getIcon();
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent i = new Intent(this, NotificationDetailActivity.class);
i.putExtra("NewsId", NewsId);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle(Html.fromHtml(remoteMessage.getNotification().getTitle()))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT))
.setSound(soundUri);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setColor(getResources().getColor(R.color.colorAccent));
} else {
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
}
Notification mNotification = mBuilder.build();
mNotification.flags |= Notification.FLAG_INSISTENT;
// Display notification
notificationManager.notify(100, mNotification);
【问题讨论】:
-
添加到意图标志:notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
你在用proguard吗?
-
@MohdSaquib 你能解释一下吗?
-
@MasoudMokhtari No
-
看看这可能对你有帮助:stackoverflow.com/questions/40417127/…
标签: android firebase firebase-cloud-messaging