【发布时间】:2017-06-24 03:11:58
【问题描述】:
我在 API 17 上发布了一条通知,并且在未点击通知的情况下触发了待处理的意图。
这是我在发布通知时使用的代码,代码的哪一部分触发了这种行为,我该如何解决?
public static void notifyIncomingMessage(Context context, ChatMessage message, String name) throws JSONException {
NotificationManager mNotificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(context, ChatMessageInterceptor.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, GcmIntentService.NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
String text = messageText(message, context);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_small_notification)
.setContentTitle(name == null ? context.getString(R.string.app_name) : name)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(text))
.setContentText(text)
.setLargeIcon(getBitmapIcon(context))
.setContentIntent(contentIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.setFullScreenIntent(contentIntent, true);
mNotificationManager.notify(GcmIntentService.NOTIFICATION_ID, mBuilder.build());
}
【问题讨论】:
-
是什么触发了意图?只是阅读通知会启动活动?或者,刚刚收到通知就是再次打开活动?
-
@GuilhermeP 当通知发布时意图触发
标签: android notifications