gpt4 book ai didi

react-native - 为什么 PermissionAndroid 不起作用?

转载 作者:行者123 更新时间:2023-12-04 05:16:10 38 4
gpt4 key购买 nike

我收到此错误:

Reference Error: can't find variable PermissionsAndroid



这是我的代码:

AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />

index.android.js:
constructor(props) {
super(props);
this.state = {
message: 'Hi world'
};
this.requestCameraPermission();
}


async requestCameraPermission() {
try {
const granted = await PermissionsAndroid.requestPermission(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
'title': 'Cool Photo App Camera Permission',
'message': 'Cool Photo App needs access to your camera ' +
'so you can take awesome pictures.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the camera")
} else {
console.log("Camera permission denied")
}
} catch (err) {
console.warn(err)
}
}

最佳答案

可能您在使用之前忘记导入组件:
import { PermissionsAndroid } from 'react-native';

关于react-native - 为什么 PermissionAndroid 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42434124/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com