且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法访问Android Q中的存储

更新时间:2023-02-09 08:32:44


这是一个临时解决方案。从Android 11开始必须使用范围存储。

This is a temporary solution. From Android 11 Scoped Storage have to be used.

问题是 requestLegacyExternalStorage 在清单文件中未设置为 true 。由于默认情况下对外部存储的作用域访问,在Android 10或更高版本中,它设置为 false 。在 AndroidManifest.xml 中添加这一行解决了我的问题。

The problem was requestLegacyExternalStorage was not set to true in the manifest file. Because of scoped access on external storage by default it is set to false in Android 10 or higher. Adding this line in the AndroidManifest.xml solved my problem.

<manifest ... >
  <!-- This attribute is "false" by default on apps targeting
       Android 10 or higher. -->
  <application 
       android:requestLegacyExternalStorage="true" ........ >
    ......
  </application>
</manifest>