ContentResolver.insert returns null
I sometimes have a problem when setting sounds as ringtones / notifications from inside an activity:
ContentValues v开发者_Python百科alues = 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?
Content providers don't support remote exceptions yet. I would look in logcat when you get the null Uri being returned. I suspect the media provider will be throwing some sort of exception.
23 ,24 should be the volume up and down for the media. uri should be the same.
精彩评论