В общем, приблизительно так:
private void changeRingtone(boolean isRingtone, boolean isNotification) {
File ringtoneFile = new File(dir, newRing);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName());
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, " ");
values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.getUsableSpace());
values.put(MediaStore.Audio.Media.IS_RINGTONE, isRingtone);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, isNotification);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile
.getAbsolutePath());
mContext.getContentResolver().delete(
uri,
MediaStore.MediaColumns.DATA + "=\""
+ ringtoneFile.getAbsolutePath() + "\"", null);
Uri newUri = mContext.getContentResolver().insert(uri, values);
try {
if (isRingtone) {
RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_RINGTONE, newUri);
}
if (isNotification) {
RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_NOTIFICATION, newUri);
}
} catch (Throwable t) {
System.err.println("Can't set ringtone");
t.printStackTrace();
}
}