Android setFullScreenIntent() 在通知到达且 phone 被锁定时执行 PendingIntent
Android setFullScreenIntent() execute the PendingIntent when notification reach and phone is locked
Android setFullScreenIntent() execute the PendingIntent when notification reach and phone is locked.
当我使用 setFullScreenIntent()
时遇到的奇怪问题它将执行我设置为内容的 PendingIntent
当我的 phone 被锁定时和当我解锁我的 phone然后打开应用程序。如果 phone 解锁并收到通知,它将在所有屏幕上将通知显示为顶部而不执行 PendingIntent
。有人遇到过这个问题吗?您的建议将不胜感激。
下面是我的代码
Intent _intent = new Intent(GcmIntentService.this,NotificationActivity.class);
_intent.addCategory(Intent.CATEGORY_DEFAULT);
_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mNotificationManager =(NotificationManager)GcmIntentService.this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(GcmIntentService.this, requestCode,
_intent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(icon)
.setTicker(ticker)
.setContentTitle(title)
.setContentText(content)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(contentIntent);
if(CURRENT_VERSION>=LOLLIPOP_VERSION){
builder.setColor(Color.argb(255, 117,63,0));
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setSmallIcon(R.drawable.app_notification_icon);
builder.setFullScreenIntent(contentIntent, false);
}
mNotificationManager.notify(NOTIFICATION_ID, builder.build());
它不适用于我的 Android 8.1。
如果将intent设置为null,它将变成普通通知,不会在单挑区持续存在。
builder.setFullScreenIntent(null, true);
如果您不想在通知到达时执行全屏 Intent,只需将空的 PendingIntent 设置为全屏 Intent。
PendingIntent fullScreenIntent = PendingIntent.getActivity(GcmIntentService.this, requestCode, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setFullScreenIntent(fullScreenIntent, true);
从意图中删除 FLAG_ACTIVITY_NEW_TASK。
Intent _intent = new Intent(GcmIntentService.this,NotificationActivity.class);
_intent.addCategory(Intent.CATEGORY_DEFAULT);
Android setFullScreenIntent() execute the PendingIntent when notification reach and phone is locked.
当我使用 setFullScreenIntent()
时遇到的奇怪问题它将执行我设置为内容的 PendingIntent
当我的 phone 被锁定时和当我解锁我的 phone然后打开应用程序。如果 phone 解锁并收到通知,它将在所有屏幕上将通知显示为顶部而不执行 PendingIntent
。有人遇到过这个问题吗?您的建议将不胜感激。
下面是我的代码
Intent _intent = new Intent(GcmIntentService.this,NotificationActivity.class);
_intent.addCategory(Intent.CATEGORY_DEFAULT);
_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mNotificationManager =(NotificationManager)GcmIntentService.this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(GcmIntentService.this, requestCode,
_intent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(icon)
.setTicker(ticker)
.setContentTitle(title)
.setContentText(content)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(contentIntent);
if(CURRENT_VERSION>=LOLLIPOP_VERSION){
builder.setColor(Color.argb(255, 117,63,0));
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setSmallIcon(R.drawable.app_notification_icon);
builder.setFullScreenIntent(contentIntent, false);
}
mNotificationManager.notify(NOTIFICATION_ID, builder.build());
它不适用于我的 Android 8.1。 如果将intent设置为null,它将变成普通通知,不会在单挑区持续存在。
builder.setFullScreenIntent(null, true);
如果您不想在通知到达时执行全屏 Intent,只需将空的 PendingIntent 设置为全屏 Intent。
PendingIntent fullScreenIntent = PendingIntent.getActivity(GcmIntentService.this, requestCode, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setFullScreenIntent(fullScreenIntent, true);
从意图中删除 FLAG_ACTIVITY_NEW_TASK。
Intent _intent = new Intent(GcmIntentService.this,NotificationActivity.class);
_intent.addCategory(Intent.CATEGORY_DEFAULT);