Environment.getExternalStorageDirectory() deprecation alternatives

后端 未结 2 1978
醉话见心
醉话见心 2021-02-14 08:55

In SDK 29 (Aka Android_Q), The access to external storage using the method Environment.getExternalStorageDirectory() is deprecated and no longer returns an accessib

相关标签:
2条回答
  • 2021-02-14 09:13

    You can use the flag android:requestLegacyExternalStorage="true" in your manifest file.

    This attribute is "false" by default on apps targeting Android 10 or higher.

    However, in future versions of Android, this permission will not be available.

    For next Android versions we should use scoped storage. More info here

    0 讨论(0)
  • 2021-02-14 09:31

    In SDK 29, I can no longer follow such a method.

    Use ACTION_OPEN_DOCUMENT_TREE to allow the user to pick a document tree, which could be a filesystem directory or something else. Then, use DocumentFile.fromTreeUri() to create a DocumentFile for that tree and use that to be able to write to documents to be stored inside of that tree.

    How will such apps migrate?

    ACTION_OPEN_DOCUMENT and ACTION_OPEN_DOCUMENT_TREE will be the two most likely on-device options. In the case of WhatsApp and Facebook, they might just elect to store the backups on their servers.

    0 讨论(0)
提交回复
热议问题