-1
我收到一条通知,我想逐渐增加声音,直到它被解雇/接听。我怎么能这样做?感谢你的帮助!Android:逐渐增加通知声音的音量
我收到一条通知,我想逐渐增加声音,直到它被解雇/接听。我怎么能这样做?感谢你的帮助!Android:逐渐增加通知声音的音量
这就是我如何执行这个任务。首先我捕捉最初的设置。毕业后,一旦用户解除通知,我会拨打另一个功能返回设置。下面是即将毕业的声音代码:
public static void graduateVolumeLevel(Context context) {
getVolumeLevel(context);
final AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final int DELAY_UNTIL_NEXT_INCREASE = 6 * 1000;
LaunchService.startThread();
mHandlerIncreaseVolume = new Handler(appService.thread.getLooper());
/*you may not need this part.
I use it b/c i run my stuff on another thread not to
interfere with the main thread.
Creating a new handler on main thread may be sufficient for your needs.*/
if(runnable==null) {
runnable = new Runnable() {
@Override
public void run() {
int currentSystemVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
int currentRingVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);
if (currentSystemVolume != mAudioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM)||
currentRingVolume != mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING)) { //if not max
//increase the volume of the alarm stream
mAudioManager.setStreamVolume(AudioManager.STREAM_RING,currentRingVolume++,0);
mAudioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, currentRingVolume++, 0);
if(mHandlerIncreaseVolume!=null)
mHandlerIncreaseVolume.postDelayed(this, DELAY_UNTIL_NEXT_INCREASE);
}
}
};
}
mHandlerIncreaseVolume.post(runnable);
}
我发现了一个类似的帖子,但无法再找到它引用它。这是我用来创建我的代码的东西,稍微修改一下,因为这个例子并没有按照原样工作。同样,一旦我返回原始设置,我从处理程序中删除回调并将其设置为null。