简体   繁体   中英

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.

Its android 11 problem To access that folder you need All Files Access Permission

<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"

Here is what you need to do:

1- In the Android Manifest file write

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

2- In app-level build.grade file put target SDK equal to "29". Add the following program in build.grade file:

...
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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