Pratik
Pratik

Reputation: 30855

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

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

Strange issue facing when I using setFullScreenIntent() it will execute the PendingIntent which I have set as content when my phone is locked and when I unlocking my phone then app is opened. If phone is unlocked and notification received it'll be display notification as top on all screen and not execute the PendingIntent. Has anybody face this issue? Your suggestion will be appreciated.

Below is my code

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());

Upvotes: 11

Views: 7472

Answers (3)

Trubitsyn Fedor
Trubitsyn Fedor

Reputation: 11

Remove FLAG_ACTIVITY_NEW_TASK from the intent.

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

Upvotes: -2

manish thanki
manish thanki

Reputation: 120

It's not working on my Android 8.1. If set the intent to null, it will become the normal notification without persist over heads-up area.

builder.setFullScreenIntent(null, true);

Upvotes: 5

Kindy
Kindy

Reputation: 57

If you do not want to execute the FullScreen Intent when notification reached,just set an empty PendingIntent to FullScreen Intent.

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

Upvotes: 2

Related Questions