【发布时间】:2022-08-16 12:01:59
【问题描述】:
我正在尝试创建一个应用程序,用户可以在按下按钮时拍照。在 app.json 上设置相机权限之前,它在我的物理设备上工作得很好,但是在 app.json 上设置权限后,它就不起作用了。我仍然收到要求用户许可的弹出窗口,但在允许使用相机后,它不会激活相机。当我再次按下按钮时它仍然不起作用。
应用程序.json
\"plugins\": [
[
\"expo-image-picker\",
{
\"photosPermission\": \"custom photos permission\",
\"cameraPermission\": \"Allow $(PRODUCT_NAME) to open the camera\",
\"//\": \"Disables the microphone permission\",
\"microphonePermission\": false
}
]
],
\"android\": {
\"package\":\"mycamera.myapp\",
\"versionCode\": 2,
\"permissions\": [\"CAMERA\",\"READ_EXTERNAL_STORAGE\"],
\"adaptiveIcon\": {
\"foregroundImage\": \"./assets/adaptive-icon.png\",
\"backgroundColor\": \"#FFFFFF\"
}
}
HomeScreen.js
const [allImage, setAllImage] = React.useState([]);
const useCamera = async () => {
const hasPermissions = await cameraPermission();
if (!hasPermissions) {
return;
}
if(allImage.length < 4){
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
quality: 0.5,
});
if (!result.cancelled) {
const name = result.uri.split(\'/\').pop();
let match = /\\.(\\w+)$/.exec(name);
let type = match ? `image/${match[1]}` : `image`;
let newFile = {
uri: result.uri,
type: type,
name: name
}
setAllImage(newFile)
setPickedImage(result.uri)
if (!pickedImage && allImage.length === 0) {
setAllImage([newFile]);
setFileName(\"Receipt 1\")
}else {
setAllImage([...allImage, newFile]);
setFileName(fileName + \", Receipt \" + (allImage.length + 1))
}
}
}
};
标签: javascript react-native android-permissions