【发布时间】:2016-07-12 12:49:17
【问题描述】:
我正在使用 FCM 接收消息,并且在 onMessageReceived 我有代码
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Service.NOTIFICATION_SERVICE);
Intent notifyIntent = new Intent(this,HelloBubblesActivity.class);
notifyIntent.putExtra("id",sender);
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentTitle("New Message from " + name)
.setSmallIcon(R.drawable.smalllogo)
.setAutoCancel(false)
.setContentText(text)
.setContentIntent(pendingIntent);
notificationManager.notify(sender, mBuilder.build());
当应用程序从通知中打开时,我遇到的问题是额外的问题是 -1,因为这里的代码
int chatId = getIntent().getIntExtra("id",-1);
我错过了什么吗?
【问题讨论】:
-
是你的
sender还是int? -
是的,肯定是 int
-
尝试在
onNewIntent中获取意图。 -
我刚刚解决了,请看我的答案
标签: android android-intent notifications