Created
May 18, 2015 07:57
-
-
Save hoseinquest/a550371fcdd89aef98bb to your computer and use it in GitHub Desktop.
Android Set Ringtone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File k = new File(path, "mysong.mp3"); // path is a file to /sdcard/media/ringtone | |
ContentValues values = new ContentValues(); | |
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath()); | |
values.put(MediaStore.MediaColumns.TITLE, "My Song title"); | |
values.put(MediaStore.MediaColumns.SIZE, 215454); | |
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); | |
values.put(MediaStore.Audio.Media.ARTIST, "Madonna"); | |
values.put(MediaStore.Audio.Media.DURATION, 230); | |
values.put(MediaStore.Audio.Media.IS_RINGTONE, true); | |
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); | |
values.put(MediaStore.Audio.Media.IS_ALARM, false); | |
values.put(MediaStore.Audio.Media.IS_MUSIC, false); | |
//Insert it into the database | |
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getA bsolutePath()); | |
Uri newUri = main.getContentResolver().insert(uri, values); | |
RingtoneManager.setActualDefaultRingtoneUri( | |
myActivity, | |
RingtoneManager.TYPE_RINGTONE, | |
newUri | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment