Android Q: file.mkdirs() returns false

前端 未结 2 577
清歌不尽
清歌不尽 2020-12-03 10:20

We have an app that uses external storage to store some temporary files: images, binary data. The code for that has been working for a few years without big changes until re

2条回答
  •  一个人的身影
    2020-12-03 10:49

    UPDATE: Since Android 11 scoped storage is enforced. Apps that target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt-out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.


    In API level 29 direct access to shared/external storage devices is deprecated. When an app targets Build.VERSION_CODES.Q, the path returned from getExternalStorageDirectory() method is no longer directly accessible to apps. Apps can continue to access content stored on shared/external storage by migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT.

    It's a best practice to use scoped storage unless your app needs access to a file that doesn't reside in the app-specific directory.

    Those who face the issue with managing files in Android-Q may read through this article to know further.

提交回复
热议问题