Android 10 ContentResolver访问Flash Drive上的MP3文件
我有在Raspberry Pi 3上运行的Android 10(lineageos)。我的USB闪存驱动器连接到Raspberry Pi,并带有大量MP3文件。我可以使用“文件”应用查看驱动器和文件,但是即使清除了媒体存储缓存和设置之后,我也无法通过ContentResolver列出这些文件中的任何一个。
借助我的Android 11手机,它具有装满MP3文件的外部SD卡,它们自动属于MediaStore数据库。
我该怎么做才能通过ContentResolver/MediaStore访问这些MP3文件?
ContentResolver musicResolver = this.getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
if (musicCursor == null) {
Log.d(TAG, "scanAndAddViaMediaStore, null cursor!");
} else {
Log.d(TAG, "scanAndAddViaMediaStore, cursor count: " + musicCursor.getCount());
}
我将获得以下调试输出:
scanAndAddViaMediaStore, cursor count: 0
我不知道这是我的编码问题,即sineageos特定问题/查询或Android问题/查询。
如果这与范围存储有关,我该如何授予MediaStore访问这些MP3文件的权限?
我在Android.manifest中有以下内容:
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
我还尝试了URI的volume_external,但这也没有帮助:
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
musicUri = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL);
}
I have Android 10 (LineageOS) running on a Raspberry Pi 3. I have a USB flash drive connected to the Raspberry Pi with a load of MP3 files. I can see the drive and files using the "Files" app but even after clearing the Media Store cache and settings, I cannot list any of these files via ContentResolver.
With my Android 11 phone, it has an external SD card full of MP3 files and they are automatically part of the MediaStore database.
What can I do to get access to these MP3 files via ContentResolver/MediaStore?
ContentResolver musicResolver = this.getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
if (musicCursor == null) {
Log.d(TAG, "scanAndAddViaMediaStore, null cursor!");
} else {
Log.d(TAG, "scanAndAddViaMediaStore, cursor count: " + musicCursor.getCount());
}
I get the below debug output:
scanAndAddViaMediaStore, cursor count: 0
I don't know if this is a coding issue on my part, a LineageOS specific issue/query or Android issue/query.
If this is related to scope storage, how can I grant permission to the MediaStore to access these MP3 files?
I have the following in my Android.manifest:
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
I also tried VOLUME_EXTERNAL for the Uri but that hasn't helped either:
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
musicUri = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论