Android setFullScreenIntent()在通知到达和手机被锁定时执行PendingIntent

时间:2015-06-27 07:46:45

标签: android notifications

Android setFullScreenIntent() execute the PendingIntent when notification reach and phone is locked.

当我使用setFullScreenIntent()时会遇到奇怪的问题,当我的手机被锁定时,当我解锁手机然后打开应用程序时,它会执行我设置为内容的PendingIntent。如果手机已解锁且收到通知,则会在所有屏幕上显示通知,并且不会执行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());

3 个答案:

答案 0 :(得分:5)

它无法在我的Android 8.1上运行。 如果将intent设置为null,它将成为正常通知,而不会持续超过抬头区域。

builder.setFullScreenIntent(null, true);

答案 1 :(得分:1)

如果您不希望在达到通知时执行FullScreen Intent,只需将空PendingIntent设置为FullScreen Intent。

PendingIntent fullScreenIntent = PendingIntent.getActivity(GcmIntentService.this, requestCode, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); builder.setFullScreenIntent(fullScreenIntent, true);

答案 2 :(得分:0)

从意图中删除FLAG_ACTIVITY_NEW_TASK。

connectedCallback()