有谁知道如何检测正在进行的通知铃声的结束? 我已经创建了一个通知,声音将设置为max 但我希望在通知铃声结束后将音量恢复为原始音量。我尝试过使用计时器但是如果有多个通知进入则无效。
以下是我目前的进展:
//get the default phone notification volume before it is set to maximum
phoneVolume = am.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
//set the phone notification volume to maximum
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION,
am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION), 0);
//initiate the notification
NotificationManagerCompat.from(this).notify(notificationId, notification);
//Set the phone notification volume back to default volume after 5 seconds
new Timer().schedule(new TimerTask() {
public void run() {
Log.i(TAG, "Phone notification volume is set back to original volume after 5 seconds");
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, phoneVolume, 0);
}
}, 5000);
赞赏建议