I wrote a piece of code to add a ringtone from a URL in Android 2.1. In Froyo it does not want to work at all.
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri
.fromFile(file)));
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA,
file.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, filenameBase);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(AudioColumns.IS_RINGTONE, true);
values.put(AudioColumns.IS_NOTIFICATION, false);
values.put(AudioColumns.IS_ALARM, false);
values.put(AudioColumns.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(file
.getAbsolutePath());
Uri newUri = RingtoneModule.this.getContentResolver()
.insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(
RingtoneModule.this, RingtoneManager.TYPE_RINGTONE,
newUri);
When I get to insert I get this exception:
11-17 09:54:51.802: ERROR/DatabaseUtils(379): java.lang.IllegalStateException: Unknown URL: content://media/external/audio/albumart/-1
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at com.android.providers.media.MediaProvider.query(MediaProvider.java:1666)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at com.android.providers.media.MediaProvider.getAlbumArtOutputUri(MediaProvider.java:2983)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at com.android.providers.media.MediaProvider.makeThumbInternal(MediaProvider.java:3192)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at com.android.providers.media.MediaProvider.getThumb(MediaProvider.java:3070)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:2029)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1843)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at android.content.ContentProvider$Transport.insert(ContentProvider.java:180)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:175)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at android.os.Binder.execTransact(Binder.java:288)
11-17 09:54:51.802: ERROR/DatabaseUtils(379): at dalvik.system.NativeStart.run(Native Method)
I google my a** of for this error but can seem to get anything info about this error.I looked at android source and the problem seems to be that when you dont have album art it generates a url "content://media/external/audio/albumart/-1" and the urlmatcher does not match any of the urls specified and then i throws this error.
URI_MATCHER.addURI("media", "*/audio/albumart", AUDIO_ALBUMART);
URI_MATCHER.addURI("media", "*/audio/albumart/#", AUDIO_ALBUMART_ID);
Does someone have any idea how I can get around that?