Reputation: 111
My alarm works well without silent and vibrate mode. When my phone is in silent and vibrate mode, How can I run the alarm. Also, how can I know alarm or music is finished.
private void mediaPlayerStart()
{
try
{
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if(alert == null)
{
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
if(alert == null)
{
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
}
ringtone = RingtoneManager.getRingtone(getApplicationContext(), alert);
ringtone.play();
}
catch (Exception e)
{
e.printStackTrace();
}
}
Upvotes: 0
Views: 96
Reputation: 56
Generally, if the user decided to mute his phone, it might be a good idea to keep it silent. However, if you're making an app for your own use, you can simply turn the volume up like so:
AudioManager mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE); mgr.setStreamVolume(AudioManager.STREAM_ALARM, mgr.getStreamMaxVolume( AudioManager.STREAM_ALARM), AudioManager.FLAG_PLAY_SOUND);
Upvotes: 1