定位Android 10时为WRITE_EXTERNAL_STORAGE [英] WRITE_EXTERNAL_STORAGE when targeting Android 10

查看:143
本文介绍了定位Android 10时为WRITE_EXTERNAL_STORAGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AS中,有一个关于 android.permission.WRITE_EXTERNAL_STORAGE 的掉毛警告.警告说,针对Android 10及更高版本,此权限将不再提供写访问权限.删除上述权限后,仍然可以在内部存储文件夹 Pictures/MY_APP_NAME 中写入以保存图像,但仅在Android 10(SDK 29)和/或更高版本上有效(尚未在Android R上进行测试).当我在较低版本(例如Android M(SDK 23))上再次对其进行测试时,保存图像停止工作,因此我决定返回 android.permission.WRITE_EXTERNAL_STORAGE ,因此警告再次出现.皮棉是否可能只是误报,从而在不同情况下错误地诊断了问题?因为目前我的支持SDK从21开始,最新的是30,但是棉绒仅指出在定位Android 10(SDK 29)时不再需要它,并且不考虑回顾该项目对SDK的最低支持.

There is a lint warning in AS with regards to android.permission.WRITE_EXTERNAL_STORAGE. The warning says that the permission will no longer provide write access when targeting Android 10 and above. Removal of the said permission can still write in internal storage folder Pictures/MY_APP_NAME to save images, but it only works on Android 10 (SDK 29) and/or above (haven't tested yet on Android R). When I tested it again on lower version such as Android M (SDK 23), saving images stop working so I decided to return the android.permission.WRITE_EXTERNAL_STORAGE thus the warning shows up again. Is it possible that the lint is just false positive that incorrectly diagnosed the problem on different cases? Because currently my support SDK starts with 21 up to the latest which is 30 but the lint only point out that it is no longer needed when targeting Android 10 (SDK 29) and did not consider looking back at the project's minimum SDK support.

推荐答案

尝试将其添加到清单中:

Try to add this in your Manifest:

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true" //Add this Line
android:label="@string/app_name">

 ---------<Activity, Sevices or Recivers>----------

</application>

并再次删除 READ_EXTERNAL_STORAGE 权限:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

这篇关于定位Android 10时为WRITE_EXTERNAL_STORAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆