I just want to disable escalating/rising/increasing volume of ringtone on incoming call. I know that there's application to do this like Disable Increasing Ring but I'm android developer, I cant see their mobile ads just to stop my phone's increasing volume ;)
I've tried this way...
public class CallReceiver extends BroadcastReceiver {
Context context;
public void onReceive(Context context, Intent intent) {
try {
this.context = context;
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
manager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE);
} catch (Exception e) {
e.printStackTrace();
}
}
private class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (state == 1 && manager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
Log.e(getClass().getSimpleName(), "Incoming call from : " + incomingNumber);
manager.setStreamVolume(
AudioManager.STREAM_RING,
manager.getStreamMaxVolume(AudioManager.STREAM_RING),
FLAG_ALLOW_RINGER_MODES | FLAG_PLAY_SOUND
);
}
}
}
}
When I put 0 volume, Phone state listener is working. But I think setStreamVolume() not working against increasing volume when I use 7 or manager.getStreamMaxVolume(AudioManager.STREAM_RING)
as volume.
Reference :