16

I was wondering if anyone has some experience with with this type of Notification.

In my use case I want to trigger a notification from my Service and than it should open a fullscreen video. The method setFullScreenIntent look just the right thing for this problem because in the documentation it writes:

An intent to launch instead of posting the notification to the status bar. Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock that the user has explicitly set to a particular time.

So it says it works like an incoming phone call. That means even if my phone is asleep I should get to see the notification in full screen.

But in my case I just get the heads-up notification and if I click on it it opens the activity. Even thought in the docs they mention something about this behavior ...

On some platforms, the system UI may choose to display a heads-up notification, instead of launching this intent, while the user is using the device.

... I want to know how to automatically open the activity when the notification is triggered. Just like the incoming phone call screen.

This is my code from the service:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {


    Intent notificationIntent = new Intent("android.intent.category.LAUNCHER");
    intent.setClassName("com.example.test",
            "com.example.test.VideoActivity");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentIntent(contentIntent)
                .setContentTitle("Video")
                .setContentText("Play video")
                .setFullScreenIntent(contentIntent, true);

    NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);



    mNotificationManager.notify(0, mBuilder.build());

    return Service.START_STICKY;
}
Aksiom
  • 1,565
  • 4
  • 25
  • 39

2 Answers2

0

try to notify notification with setFullScreenIntent at onCreate

@Override
public int onCreate() {
    Intent notificationIntent = new Intent("android.intent.category.LAUNCHER");
    intent.setClassName("com.example.test",
        "com.example.test.VideoActivity");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(contentIntent)
            .setContentTitle("Video")
            .setContentText("Play video")
            .setFullScreenIntent(contentIntent, true);

    NotificationManager mNotificationManager = (NotificationManager) 
   this.getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(0, mBuilder.build());
}
임진성
  • 1
  • 1
-3

Try removing

.setContentIntent(contentIntent)
Peh Qin Cheng
  • 73
  • 1
  • 8