我在 API 17 上发布了一个通知,并且在没有点击通知的情况下触发了未决 Intent 。
这是我在发布通知时使用的代码,代码的哪一部分触发了此行为,我该如何解决?
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());
}
最佳答案
主要原因是 setFullScreenIntent() 方法,android 的文档告诉 [developer.android.com][1] 所以不要使用
mBuilder.setFullScreenIntent(contentIntent, true);
而只是使用
mBuilder.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL);
这将有助于默认显示提醒通知。 即使对于 setDefaults(),Notification.DEFAULT_ALL 也不是必需的,但很好用。
这很清楚,对我有用。
关于android - API 17 - Android 通知在不被点击的情况下启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35626662/