gpt4 book ai didi

android - 如何在 Flutter 中授予访问外部存储的权限

转载 作者:行者123 更新时间:2023-12-03 03:32:42 28 4
gpt4 key购买 nike

当我在 flutter 代码中使用以下行时:

print(Directory("/sdcard").list(recursive: true).listen((event) {print(event);}));
我收到以下错误:
"[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FileSystemException: Directory listing failed, path = '/sdcard/' (OS Error: Permission denied, errno = 13)"
我尝试将这些添加到 list 选项卡下的 AndroidManifest.xml :
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
但它没有用。我也尝试在flutter clean后重新运行它,但我仍然得到了相同的结果。
有人可以帮我解决这个问题。
我的主要目标是能够访问(读/写)android/ios 设备存储中存在的所有可访问目录。就像我们的普通手机文件管理器一样。
非常感谢您的回答。

最佳答案

我的建议是避免这样做。
从 Android 10 开始,通过 scoped storage 的实现,对共享存储的访问受到了很大限制。 .不再允许通过文件系统路径访问文件,除非它是您有限范围存储的一部分。
除非绝对需要通过绝对路径访问共享存储,否则您应该使用 Storage Access Framework 或 MediaStore API。
Android 11 只会强制执行更多这些限制。
All files access

The majority of apps that require shared storage access can follow scoped storage best practices such as the Storage Access Framework or MediaStore API. However, some apps have a core use case that requires broad access of files on a device, but cannot do so efficiently using the privacy-friendly storage best practices.

For example, an anti-virus app's primary use case might require regular scanning of many files across different directories. If this scanning requires repeated user interactions to select directories using the system file picker, it may provide a poor user experience. Other use cases—such as file manager apps, backup and restore apps, and document management apps—may require similar considerations.

An app can request a special app access called All files access from the user by doing the following:

Declare the MANAGE_EXTERNAL_STORAGE permission in the manifest.Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page where they can enable the following option for your app: Allow access to manage all files.


考虑到 requirements让应用程序能够使用 MANAGE_EXTERNAL_STORAGE因为它不允许每个人

Google Play restricts the use of high risk or sensitive permissions, including a special app access called All files access.

If your app does not require access to the all files access permission, you must remove it from your app's manifest in order to successfully publish your app. Details on policy-compliant alternative implementations are also detailed below.

If your app meets the policy requirements for acceptable use or is eligible for an exception, you will be required to declare this and any other high risk permissions using the Declaration Form in the Play Console.

Apps that fail to meet policy requirements or do not submit a Declaration Form may be removed from Google Play.https://support.google.com/googleplay/android-developer/answer/9956427?hl=en

关于android - 如何在 Flutter 中授予访问外部存储的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62974799/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com