as the android system continues to update, a lot of business code to follow the update, otherwise often unexpected errors will occur. For example, starting with Android Q(10), storage is partitioned. As a result, I have applied for the permission of Android.Permission.WRITE_EXTERNAL_STORAGE, but I still report open Failed: EACCES (Permission denied). You can only turn permissions on manually, and you can also use storage permissions.
without further ado, let’s talk about the solution first, then the principle. The solution is to add
to the manifest’s application tag
android:requestLegacyExternalStorage="true" 标识,问题便解决了。如图:
p>
here’s why: the Android Q file storage mechanism has been modified to sandbox mode, a bit like apple. APP can only access files in its own directory and public media files. Under AndroidQ, use the old file storage method. Android Q still USES READ_EXTERNAL_STORAGE
and WRITE_EXTERNAL_STORAGE
as storage related runtime permissions, but now access to external storage is limited even if these permissions are obtained.
android:requestLegacyExternalStorage="true" 的意思就是使用旧的存储策略,不使用androidQ的新策略。但这个不是长久之计,很快将会强制都使用新策略。最好的解决策略就是
1.需要长期保存并且卸载也不能删除的,使用公有目录
public directory: Downloads
Documents
Downloads Downloads Documents
Downloads Documents p> Downloads