Today we have seen how to change the modes of phone using audio manager in Android.
1)Declare the Audio manager class.
AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
2)Next, we have to perform an action on particular button to change the mode.
@Override
public void onClick(View view) {
switch (view.getId())
{
//For Normal Mode
case R.id.btn_normal:
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
//For Silent Mode
case R.id.btn_silent:
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
//For Vibrate Mode
case R.id.btn_dnd:
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
break;
}
}
Thanks..
1)Declare the Audio manager class.
AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
2)Next, we have to perform an action on particular button to change the mode.
@Override
public void onClick(View view) {
switch (view.getId())
{
//For Normal Mode
case R.id.btn_normal:
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
//For Silent Mode
case R.id.btn_silent:
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
//For Vibrate Mode
case R.id.btn_dnd:
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
break;
}
}
Thanks..



0 comments:
Post a Comment