开发者

Don't overwrite existing Notification

For a given Notification ID is it possible (using standard android packages) not to set a notification if there is an existing notificati开发者_如何学运维on from the app ?

I have a news application notifying users on breaking news headlines, one of the requirement is not to over write a breaking news if the user has not cleared it or has not clicked to view it.

Im using a SharedPreference to set a flag to figure out if Im already showing a headline plus a delete intent that'll clear it. However the deleteIntent isn't always invoked when the user clears all notification.

Thanks in advance.

Sandeep


For anyone following this later:

There's no easy way to not to overwrite a existing Notification ID using the SDK. The way to do this is:

  • use a boolean flag via SharedPreference, if this flag is set then don't write the notification
  • reset this flag when the user "Clear"s all notification. To do this setup a deleteIntent (via a Service), make sure you clear this flag in the onStartCommand() and onStart()
  • optionally reset the flag when the app is launched


If your requirement is :

one of the requirement is not to over write a breaking news if the user has not cleared it or has not clicked to view it.

You can use NotificationManager for getting list of all the active notifications posted by your application using getActiveNotifications()

And check if the user has dismissed or opened the notification and take the required action.

As per the reference doc for getActiveNotifications():

Recover a list of active notifications: ones that have been posted by the calling app that have not yet been dismissed by the user or cancelled by the app.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜