Reputation: 11
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
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