shweta naik
shweta naik

Reputation: 1

play loud ring tone/music irrespective of which profile it is in

i want to play any ring tone/song music irrespective of whether it is in silent mode or vibration mode or any other mode. the code i am using to play a ring tone is

 Uri ringtoneUri =  RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
                Ringtone ringtoneSound;
                ringtoneSound=RingtoneManager.getRingtone(context, ringtoneUri);
                if (ringtoneSound != null) {
                    ringtoneSound.play();
                }

but ring tone plays only when mobile volume is high. is there any way to increase the volume of android device ? so that i can increase the volume of my android device and then run the above code.

Upvotes: 0

Views: 251

Answers (1)

Wildcopper
Wildcopper

Reputation: 373

This should work to set the volume if the phone is a profile authorizing sound.

public void setAlarmVolume(int iVol) {
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (am!=null) {
        int maxVol = am.getStreamMaxVolume(AudioManager.STREAM_ALARM);
        int volume = (maxVol*iVol)/100;
        am.setStreamVolume(AudioManager.STREAM_ALARM, volume, 0);
    }
}

iVol is the volume in percent (0 to 100).

Keep in mind that if the device is set on vibration only or on silence, you still won't get sound, and quite rightfully so. You can't bypass the user's wish not to have sound.

Upvotes: 1

Related Questions