Arnaud Regnier
Arnaud Regnier

Reputation: 11

Use the volume of alarm, and not that of the call

I devlop an application of wakeup . The problem is that, the application uses the volume of calls and sms . and not that of the alarm.

 public void onReceive(Context context, Intent intent) {

            Uri uri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_ALARM);

            Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
            ringtone = RingtoneManager.getRingtone(context, alert);
            ringtone.play();

Upvotes: 0

Views: 751

Answers (2)

Walk
Walk

Reputation: 757

DavidH's answer works but Ringtone.setStreamType was deprecated in API level 21. For API level 21+ use:

ringtone.setAudioAttributes(new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM).build());

To support older Android versions:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      ringtone.setAudioAttributes(new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM).build());
} else {
      ringtone.setStreamType(AudioManager.STREAM_ALARM);
}

Upvotes: 2

David Heisnam
David Heisnam

Reputation: 2491

Use

ringtone.setStreamType(AudioManager.STREAM_ALARM);

Upvotes: 0

Related Questions