我无法将文件写入外部存储(例如
/storage/emulated/0/Example
)。
我当前的配置如下:
targetSdk: 33
WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE added
"storage" permission request at runtime (Permission.storage.request())
使用此配置,在运行时检查存储权限时,我总是得到一个
"permanently denied"
。因此我在 AndroidManifest 中添加了以下内容:
android:requestLegacyExternalStorage="true"
有了这个改变,我在运行时得到一个权限请求窗口,我可以确认我的应用程序可以使用这个权限。
现在权限检查返回
"granted"
,但是如果我尝试写一个文件,例如/storage/emulated/0/Example/test.txt
我得到一个错误:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot open file, path = '/storage/emulated/0/Example/test.txt' (OS Error: Operation not permitted, errno = 1)
然后我尝试使用适用于 Android 13 的粒度媒体权限:
READ_MEDIA_IMAGES, READ_MEDIA_AUDIO, READ_MEDIA_VIDEO
这对我也不起作用。
我得到这个工作的唯一方法是定义
MANAGE_EXTERNAL_STORAGE
权限。但是,如果我上传我的 appbundle,谷歌会因为这个权限而拒绝它。
对于这个要求我还有什么其他选择:
Flutter
targetSdk > 33
allow user to save files to any folder he wants
do not use MANAGE_EXTERNAL_STORAGE
谢谢!