Set as ringtoon successfully on Orea 8.1 Problem Solved
I'm trying to find a way to set a new default ringtone by code from my Android activity.
An Here What I Did and Its Working
Finally, I managed to set the default ringtone to one that i downloaded.
Finally, I managed to set the default ringtone to one that i downloaded.
The download code is not included below, only what was needed to set it as default ringtone.
Hope This Code Will Work For You
File k = new File(mpath); // path is a file to /sdcard/media/ringtone
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, album);
values.put(MediaStore.MediaColumns.SIZE, 215454);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, title);
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);
Hope This Code Will Work For You
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
HomeActivity.this.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);
Uri newUri = main.getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(),
RingtoneManager.TYPE_RINGTONE,
newUri
);
Post a Comment
0Comments