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

问题描述 投票:5回答:3
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());
android notifications
3个回答
5
投票

它不适用于我的Android 8.1。如果将intent设置为null,它将成为正常通知,而不会持续超过抬头区域。

builder.setFullScreenIntent(null, true);

1
投票

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

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


0
投票

从意图中删除FLAG_ACTIVITY_NEW_TASK。

Intent _intent = new Intent(GcmIntentService.this,NotificationActivity.class); _intent.addCategory(Intent.CATEGORY_DEFAULT);

© www.soinside.com 2019 - 2024. All rights reserved.