在 android 10 中读写权限收到限制,
需在 AndroidMainfest.xml 中添加以下代码
<application
android:requestLegacyExternalStorage="true"
/>
有可能还会出现此问题,需要给对应的需要读写权限的 APP 再次授权,获取读写权限代码:
public static void getPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
try {
mDevice.executeShellCommand("pm grant " + InstrumentationRegistry.getTargetContext().getPackageName() + " android.permission.READ_EXTERNAL_STORAGE");
mDevice.executeShellCommand("pm grant " + InstrumentationRegistry.getTargetContext().getPackageName() + " android.permission.WRITE_EXTERNAL_STORAGE");
} catch (IOException e) {
e.printStackTrace();
}
}
}
本文介绍在Android10系统中如何解决应用的读写权限受限问题,包括在AndroidManifest.xml中添加请求遗留外部存储权限代码,以及通过执行Shell命令再次授权,确保应用程序能正常访问外部存储。
4968

被折叠的 条评论
为什么被折叠?



