我在用着"react-native-image-picker": "^3.0.1"
在本机反应中捕获图像。但我在 android 9 中打开相机时出错。
我收到错误:
{"errorCode": "others", "errorMessage": "This library does not require Manifest.permission.CAMERA, if you add this permission in manifest then you have to obtain the same."}
这是我的代码
ImagePicker.launchCamera(
{
includeBase64: false,
mediaType: 'photo',
quality: 0.8,
},
async (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else {
}
},
);
在拍摄图像之前,询问相机许可给用户。在Android上面棉花糖你应该问的版本Run Time也称为危险许可。
const requestCameraPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
title: "App Camera Permission",
message:"App needs access to your camera ",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Camera permission given");
} else {
console.log("Camera permission denied");
}
} catch (err) {
console.warn(err);
}
};
然后如果获得许可然后在里面if
call
ImagePicker.launchCamera
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)