Android Alarm Volume increase gradually
android, android-alarms, android-audiomanager, media, volume
Solution
You can do it by yourself. Nothing complicated in it.
Once your `PendingIntent` is triggered, make use of handlers to do the increasing.
Create class that will take the `AudioManager` or `Context` of the app as argument.
public class VolumeRunnable implements Runnable{
private AudioManager mAudioManager;
private Handler mHandlerThatWillIncreaseVolume;
private final static int DELAY_UNTILL_NEXT_INCREASE = 30*1000;//30 seconds between each increment
VolumeRunnable(AudioManager audioManager, Handler handler){
this.mAudioManager = audioManager;
this.mHandlerThatWillIncreaseVolume = handler;
}
@Override
public void run(){
int currentAlarmVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
if(currentAlarmVolume != mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)){ //if we havent reached the max
//here increase the volume of the alarm stream by adding currentAlarmVolume+someNewFactor
mHandlerThatWillIncreaseVolume.postDelayed(this,DELAY_UNTILL_NEXT_INCREASE); //"recursively call this runnable again with some delay between each increment of the volume, untill the condition above is satisfied.
}
}
}
Call this `Runnable` once the `PendingIntent` is triggered:
someHandler.post(new VolumeRunnable(mAudioManager, someHandler));
I hope this gave you idea. Forgive any mistakes or typos.
Problem
I have an Alarm class which plays the default alarm tone on time. I want to make the alarm tone play, volume from minimum to maximum within a time. How can i increase the volume gradually from minimum to maximum. Is there any links for sample codes or projects. please help me