Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to reduce notification time showing in Android?

I am using bellow code to show a notification on my Android phone. I want to reduce the time which uses to shows the notification. Now, it spends about 2 seconds for showing, then it is hidden. I want to reduce the time from 2 seconds to 1 second. Is it possible?

Notification notification = new NotificationCompat.Builder(context)
                    .setContentTitle(context.getString(R.string.app_name))
                    .setContentText("Notification")
                    .setAutoCancel(false)
                    .setPriority(Notification.PRIORITY_MAX)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                    .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
                    .build();

NotificationManager notificationManager = getNotificationManager(context);
notificationManager.notify(SAFER_DISCONNECTED_NOTIFICATION_ID, notification);
like image 753
Jame Avatar asked Oct 29 '22 16:10

Jame


1 Answers

Now, it spends about 2 seconds for showing, then it is hidden.

There is no particular guarantee regarding the amount of time that a Notification will be shown in heads-up mode, which I assume is what you are referring to.

For example, by default it will be shown for 0 seconds on Android 4.4 and earlier, which does not natively support heads-up notifications. However, a user could install an app with a NotificationListenerService, and that service could display the notification however, and for however long, it wants.

Is it possible?

No, sorry. That is under the control of the code that displays the notifications.

like image 121
CommonsWare Avatar answered Nov 15 '22 05:11

CommonsWare