在 Android Q 中引入了 Scoped Storage,我应该如何开发文件管理器应用程序?
With Scoped Storage introduced in Android Q, how am I supposed to develop a file manager app?
Android Q 将为应用程序引入一个新的沙盒文件系统,Scoped Storage。此政策将针对 API>=29 的所有应用强制执行。第三方文件管理器应用程序应该如何通过此限制并继续正常工作?
此问题适用于具有某些文件管理功能(如浏览、保存、加载、同步等)的任何应用程序。
我相信您的问题等同于:应用程序如何访问主 phone 存储(通常 /sdcard
)?
答案是:要求用户使用 ACTION_OPEN_DOCUMENT_TREE
操作访问整个 /sdcard
。这样您的应用程序就可以访问 /sdcard
及其所有子目录。
来自 https://developer.android.com/preview/privacy/scoped-storage#manage-groups-of-files :
File management and media creation apps typically manage groups of files in a directory hierarchy. These apps can invoke the ACTION_OPEN_DOCUMENT_TREE intent to allow the user to grant access to an entire directory tree. Such an app would be able to edit any file in the selected directory, as well as any of its sub-directories.
Using this interface, users can access files from any installed instance of DocumentsProvider, which any locally-backed or cloud-based solution can support.
Github 上还有示例项目展示了它是如何完成的:https://github.com/android/storage/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree
这就是“Google 的文件”目前在 Android Q 测试版上所做的:https://www.androidpolice.com/2019/04/08/scoped-storage-in-android-q-beta-2-limits-how-apps-can-access-files/#1
Android Q 将为应用程序引入一个新的沙盒文件系统,Scoped Storage。此政策将针对 API>=29 的所有应用强制执行。第三方文件管理器应用程序应该如何通过此限制并继续正常工作?
此问题适用于具有某些文件管理功能(如浏览、保存、加载、同步等)的任何应用程序。
我相信您的问题等同于:应用程序如何访问主 phone 存储(通常 /sdcard
)?
答案是:要求用户使用 ACTION_OPEN_DOCUMENT_TREE
操作访问整个 /sdcard
。这样您的应用程序就可以访问 /sdcard
及其所有子目录。
来自 https://developer.android.com/preview/privacy/scoped-storage#manage-groups-of-files :
File management and media creation apps typically manage groups of files in a directory hierarchy. These apps can invoke the ACTION_OPEN_DOCUMENT_TREE intent to allow the user to grant access to an entire directory tree. Such an app would be able to edit any file in the selected directory, as well as any of its sub-directories.
Using this interface, users can access files from any installed instance of DocumentsProvider, which any locally-backed or cloud-based solution can support.
Github 上还有示例项目展示了它是如何完成的:https://github.com/android/storage/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree
这就是“Google 的文件”目前在 Android Q 测试版上所做的:https://www.androidpolice.com/2019/04/08/scoped-storage-in-android-q-beta-2-limits-how-apps-can-access-files/#1