ContentResolver.insert returns null
Asked Answered
B

2

6

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?

Barouche answered 3/12, 2010 at 9:35 Comment(0)
C
7

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.

Coster answered 4/12, 2010 at 7:34 Comment(0)
A
1

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

Antoinetteanton answered 3/12, 2010 at 10:17 Comment(1)
I had the impression the insert function returns a unique uri for every different ringtone you add?Barouche

© 2022 - 2024 — McMap. All rights reserved.