Is it possible to set how long a notification is displayed in android API level 10 or lower?

StackOverflow https://stackoverflow.com/questions/12975067

Вопрос

Research

I've been looking through the NotificationManager class in the android documentation for API level 10 and haven't found a way to implement this. I also looked around on google but only found how to set the time at which the notification is actually set and how to set the length of time a toast notification widget is displayed.


Currently Implemented

I have already set the FLAG_NO_CLEAR and FLAG_ONGOING_EVENT to keep the notification icon present as well as keep the notification visible after expanding the notification drop-down.


Attempting to Do

I am attempting to display the text of the notification in the notification bar for 10 seconds instead of the standard amount of time. So I would basically like to do exactly what the setDuration(int) function does in the toast widget.

I was wondering if this was possible and if so if someone could point me in the right direction on how to accomplish it.

Это было полезно?

Решение

I am attempting to display the text of the notification in the notification bar for 10 seconds instead of the standard amount of time.

If "the text of the notification in the notification bar" means the ticker text (e.g., setTicker() on your Builder), you do not control that duration.

If "the text of the notification in the notification bar" means something in the notification drawer entry, you are welcome to cancel() your notification after a period of time.

Другие советы

I am not convinced that this is a behavior users would expect (they may not have a look at the device within 10s)

Having said that, you may try to set an alarm, that fires 10s in the future, and which cancels the notification.

If you want a short notice for a user that is looking at the screen already, you may be better off with using a Toast.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top