-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に設定されます。