简体   繁体   中英

How do I perform an action when an Android Notification is complete?

I have a service that starts a broadcastReceiver to listen for an SMS. If the specific SMS is received it sets the notification volume to maximum and fires a notification.

How can I return the volume to the previous setting AFTER the notification has completed?

There is no notion of a "notification has completed".

If you mean "when the sound for my notification has completed", you know how long the sound is. Use AlarmManager to schedule an alarm to get notified after that amount of time has elapsed (perhaps plus a second or two, to be sure), and then change the volume back when that alarm goes off.

Or, better yet, don't mess with the volume in the first place.

You can't do this directly, and as a workaround you can try to get the current notification sound's length, wait for that specific period, and then change the volume. I don't think it's very reliable though ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM