This code will set your ringtone for ANDROID.

String filepath ="/sdcard/myring.mp3";
File ringtoneFile = new File(filepath);

To set a ringtone you have to add it to the database.
otherwise it will not be set also gives no error also.

ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.TITLE, "test");
content.put(MediaStore.MediaColumns.SIZE, 215454);
content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
content.put(MediaStore.Audio.Media.ARTIST, "artist");
content.put(MediaStore.Audio.Media.DURATION, 230);
content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
content.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
content.put(MediaStore.Audio.Media.IS_ALARM, false);
content.put(MediaStore.Audio.Media.IS_MUSIC, false);

Insert it into the database

Log.i(TAG, "the absolute path of the file is :"+ringtoneFile.getAbsolutePath());
Uri uri = MediaStore.Audio.Media.getContentUriForPath(
Uri newUri = context.getContentResolver().insert(uri, content);
ringtoneUri = newUri;
Log.i(TAG,"the ringtone uri is :"+ringtoneUri);

Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.