简体   繁体   English

如何使用存储访问框架访问“/storage/emulated/0/Android/media/”?

[英]How to get access to "/storage/emulated/0/Android/media/" using Storage Access Framework?

我正在开发一个应用程序,我想访问“/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/.Statuses”来为我的应用程序获取状态文件夹中的数据。

Do you have to use the Storage Access Framework?您是否必须使用存储访问框架? If you have access to the directories you are describing, you should be able to use the Java "File" library to perform all of your file/directory access tasks.如果您有权访问所描述的目录,则应该能够使用 Java“文件”库来执行所有文件/目录访问任务。

Its android 11 problem To access that folder you need All Files Access Permission它的 android 11 问题要访问该文件夹,您需要所有文件访问权限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
    android:maxSdkVersion='28'/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> //---This

Make sure to ask that permission.请务必征得该许可。

I have been able to solve this problem by downgrading the target SDK version to "29"我已经能够通过将目标 SDK 版本降级到“29”来解决这个问题

Here is what you need to do:以下是您需要做的:

1- In the Android Manifest file write 1-在Android Manifest文件中写入

...
 <application
        android:requestLegacyExternalStorage="true"
...

2- In app-level build.grade file put target SDK equal to "29". 2- 在应用级 build.grade 文件中,将目标 SDK 设为“29”。 Add the following program in build.grade file:在 build.grade 文件中添加以下程序:

...
android {
  defaultConfig {
    minSdkVersion 19
    targetSdkVersion 29
  }
}
...

Also, note that targetSdkVersion 30 will cause android:requestLegacyExternalStorage="true" to be ignored, so we have to downgrade it to 29 (Android 10) for this thing to work另外,请注意 targetSdkVersion 30 会导致 android:requestLegacyExternalStorage="true" 被忽略,所以我们必须将它降级到 29 (Android 10) 才能让这个东西工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM