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开发者_JS百科 setting AFTER the notification has completed?
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 ...
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.
精彩评论