Unable To Set As Ringtone Because File Already Exists
I am trying to make app with set as ringtone feature but I got a problem. When I Set as ringtone once it's working. But when I try to set as ringtone for second time, nothing happe
Solution 1:
adjust your code like this:
if (!rsound.exists()) {
//your create sound file code here.
} else {
//call set ringtone method also for the case file exists:setRingtone();
}
Solution 2:
Audio is set as ringtone only once, but solution to this problem is - If you are trying to run the same code again, you'll be inserting a duplicate entry into MediaStore's table, but the SQLite database won't allow you. You have to either rename your file and add another instance of it, or go in, remove the entry, and then try again. So I removed that entry every time and then insert it again.
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);
Uri newUri = getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(activity.this,
RingtoneManager.TYPE_RINGTONE, newUri);
Post a Comment for "Unable To Set As Ringtone Because File Already Exists"