Setting custom alarm tone in Android plays default tone instead
Asked Answered
P

0

6

I am writing a soundboard app and want to set custom ogg files as ringtone, notification tone and alarm tone. I am using RingtoneManager to do this:

// register with MediaStore content provider
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, soundName);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
values.put(MediaStore.MediaColumns.SIZE, newSoundFile.length());
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

// delete row if it exists
Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newSoundFile.getAbsolutePath() + "\"", null);

Uri newUri = getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM, newUri);

It works for ringtones and notifications (by replacing TYPE_ALARM) but not for alarm. Instead, it just plays the default Android notification sound.

Does anybody have the same problem or possibly a solution?

Puritanism answered 21/11, 2011 at 11:58 Comment(3)
Visit this #1272277Aubert
I already know how to set a ringtone, it just does not work for alarm tonesPuritanism
Could you please post the logs when you are setting the alarm?Lavernelaverock

© 2022 - 2024 — McMap. All rights reserved.