gpt4 book ai didi

android - java.lang.IllegalArgumentException 在 Android 10 设备中找不到卷 external_primary

转载 作者:行者123 更新时间:2023-12-03 14:31:47 30 4
gpt4 key购买 nike

崩溃:java.lang.IllegalArgumentException 卷 external_primary 未找到
从媒体商店查询轨道时,我在一些 Android 10 设备中遇到了这种崩溃(其中大多数来自小米 Mi A2 Lite、摩托罗拉、HMD Global Nokia)。Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);我应该为 Android 10 设备传递不同的 URI 吗? (但是它在大多数设备中都可以正常工作)
堆栈跟踪 :

Caused by java.lang.IllegalArgumentException: Volume external_primary not found
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.query(ContentProviderProxy.java:423)
at android.content.ContentResolver.query(ContentResolver.java:946)
at android.content.ContentResolver.query(ContentResolver.java:881)
at android.content.ContentResolver.query(ContentResolver.java:837)
at com.example.musicplayer.CursorFactory.getAllSongsCursor(CursorFactory.java:164)
编辑:基于此 issue据报道,怀疑这可能是那些装有 Android 10 操作系统的设备中的 sdcard 问题。

最佳答案

在 Android 10、API 28 之后,从其他来源访问媒体内容时会有一些变化。
谷歌在此链接中提到它 https://developer.android.com/training/data-storage/shared/media#storage-volume
您可以通过 google 提供的更多信息以及以下代码获取有关如何解决此问题的更多信息:

// Add a specific media item.
ContentResolver resolver = getApplicationContext()
.getContentResolver();

// Find all audio files on the primary external storage device.
// On API <= 28, use VOLUME_EXTERNAL instead.
Uri audioCollection = MediaStore.Audio.Media.getContentUri(
MediaStore.VOLUME_EXTERNAL_PRIMARY);

// Publish a new song.
ContentValues newSongDetails = new ContentValues();
newSongDetails.put(MediaStore.Audio.Media.DISPLAY_NAME,
"My Song.mp3");

// Keeps a handle to the new song's URI in case we need to modify it
// later.
Uri myFavoriteSongUri = resolver
.insert(audioCollection, newSongDetails);
希望这对你有用!

关于android - java.lang.IllegalArgumentException 在 Android 10 设备中找不到卷 external_primary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63111091/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com