我正在尝试将 XSPF 播放列表从外部存储插入到 Android Q Media Provider 数据库播放列表表。但得到异常。
public static void insertXSPFPlayListTable(Context context, MediaFile file) {
//insert audio_playlists table
Uri uri = MediaStore.Files.getContentUri("external");
context.getContentResolver().delete(uri, "_data = ?",
new String[]{file.getFilePath()});
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Audio.Playlists.DATA, file.getFilePath());
contentValues.put(MediaStore.Audio.Playlists.DATE_MODIFIED, file.getLastModified());
contentValues.put(MediaStore.Audio.Playlists.NAME, file.getFileName());
Uri insertUri = context.getContentResolver().insert(
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, contentValues);
if (insertUri != null) {
int mPlaylistId = -1;
Cursor c = context.getContentResolver().query(insertUri, PROJECTION_PLAYLIST, null, null, null);
if (c != null) {
mPlaylistId = c.getInt(c.getColumnIndex(MediaStore.Audio.Playlists._ID));
c.close();
}
}
int newId = Integer.parseInt(insertUri.getLastPathSegment());
file.setId(newId);
}
例外:
DatabaseUtils: java.lang.IllegalArgumentException: Requested path /storage/24E7-9DBA/testdata/PlayList/XSPF1/Test.xspf doesn't appear under [/storage/emulated/10]
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at com.android.providers.media.MediaProvider.insertFile(MediaProvider.java:2498)
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3158)
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at com.android.providers.media.MediaProvider.insert(MediaProvider.java:2903)
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at android.content.ContentProvider$Transport.insert(ContentProvider.java:309)
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:154)
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at android.os.Binder.execTransactInternal(Binder.java:1021)
05-12 13:14:36.627 3678 3697 E DatabaseUtils: at android.os.Binder.execTransact(Binder.java:994)