应用环境详情-
"react": "18.2.0",
"react-native": "0.71.7",
"react-native-permissions": "^3.8.0",
"react-native-webview": "^12.0.2"
测试设备详情-
Name - sdk_gphone64_x86_64
SDK version - 33
Android version- 13
我想在我的应用程序中添加WRITE_EXTERNAL_STORAGE
权限,因此我做了这些更改-AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/AppTheme"
>
...
</application>
但是当我安装应用程序时,它并没有要求将数据写入外部存储的权限。此外,当我检查应用程序的配置时,只列出了相机权限。
在我的JS代码中,当我检查并请求此权限时,响应总是阻塞。
// INITIALLY THIS FUNCTION GETS CALLED ON CLICK OF SOME ACTION
async checkPermission(permissionType: any) {
// permissionType is "WRITE_EXTERNAL_STORAGE"
await request(
Platform.select({
android: PERMISSIONS.ANDROID[permissionType],
}),
).then((response: string) => {
if (response !== 'authorized') {
// CONTROL GOES HERE
this.requestPermissions(permissionType);
}
});
}
async requestPermissions(permissionType: any) {
await request(
Platform.select({
android: PERMISSIONS.ANDROID[permissionType],
}),
).then(response => {
if (['restricted', 'blocked', 'never_ask_again'].includes(response)) {
// CONTROL GOES HERE BECAUSE RESPONSE IS ALWAYS BLOCKED
}
});
}
我不明白为什么存储权限不起作用。React native新版本中有什么变化吗?
1条答案
按热度按时间svmlkihl1#
当您在API级别33中检查代码时(Android 13),你必须跳过检查,并要求从API级别33的
WRITE_EXTERNAL_STORAGE
的权限,因为新的android版本已经引入了存储访问的限制,并提供安全的方式来访问数据。建议始终只将数据写入应用程序目录(缓存目录),如果没有必要向用户显示数据。有关存储更改的更多信息,请参阅此文档友情链接:
https://developer.android.com/about/versions/11/privacy/storage
https://developer.android.com/training/data-storage/shared/media
https://stackoverflow.com/a/74296799/5696047