Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentResolver.insert returns null

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?

like image 724
Froghut Avatar asked Dec 03 '10 09:12

Froghut


2 Answers

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.

like image 152
Nic Strong Avatar answered Dec 01 '22 04:12

Nic Strong


23 ,24 should be the volume up and down for the media. uri should be the same.

like image 21
garima Avatar answered Dec 01 '22 04:12

garima