NotificationCompat and setFullScreenIntent ()

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

In my case, I want to call a notification from my Service, and it should open a full-screen video. The setFullScreenIntent method looks right for this problem, because in the documentation he writes:

The ability to run instead of sending a notification to the status bar. Only for use with extremely high-priority notifications that require the user's immediate attention, such as an incoming phone call or alarm, which the user explicitly set at a specific time.

So he says that it works like an incoming phone call. This means that even if my phone is asleep, I should see a notification in full screen mode.

But in my case, I just get a heads-up notification, and if I click on it, it will open the action. Even thoughts in the docs mention something about this behavior ...

On some platforms, the system user interface may choose to display heads-up notifications instead of launching this intention when the user uses the device.

... I want to know how to automatically open an action when a notification is triggered. Just like the incoming 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; } 
+5
source share
1 answer

Try to remove

 .setContentIntent(contentIntent) 
0
source

Source: https://habr.com/ru/post/1209452/


All Articles