I sometimes have a problem when setting sounds as ringtones / notifications from inside an activity:
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, source);
values.put(MediaStore.MediaColumns.TITLE, "abc");
values.put(MediaStore.MediaColumns.SIZE, new File(source).length());
values.put(MediaStore.MediaColumns.MIME_TYPE, mime);
values.put(MediaStore.Audio.Media.ARTIST, "xyz");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
final Uri curi = MediaStore.Audio.Media.getContentUriForPath(source);
Uri uri = getContentResolver().insert(curi, values);
most time uri is something like "content://media/external/audio/media/23", but sometimes it is null. I don't know where the problem lies, the audio files are ok (they play ok) and obviously the insert method does not throw any exception. I looked through the documentation but there is nothing about the method returning null. What could be the problem?