无法打开移动的摄像头,而使用expo Go应用程序在Android?相机是不是在react原生expo应用程序在Android真实的设备中打开,Incase我点击按钮打开相机,它显示一些警告消息。但如果我建立APK,相机是打开的,工作正常
import {
launchCameraAsync,
useCameraPermissions,
PermissionStatus,
} from 'expo-image-picker';
import { Alert, Button, View } from 'react-native';
const ImagePicker = () => {
const [cameraPermissionInformation, requestPermission] =
useCameraPermissions();
const verifyPermission = async () => {
console.log('PermissionStatus.DENIED', PermissionStatus.DENIED);
if (cameraPermissionInformation.status === PermissionStatus.UNDETERMINED) {
const responseStatus = await requestPermission();
return responseStatus.granted;
}
if (cameraPermissionInformation.status === PermissionStatus.DENIED) {
// Alert.alert(
// 'Insufficient Camera Permission!',
// 'This app need camera permission'
// );
const permissionResponse = await requestPermission();
console.log(
'permissionResponse.granted-----',
permissionResponse.granted
);
return permissionResponse;
// return false;
}
return true;
};
const imagePickerHandler = async () => {
const hasPermission = await verifyPermission();
console.log('hasPermission ', hasPermission);
if (!hasPermission) {
return;
}
const image = await launchCameraAsync({
allowsEditing: true,
aspect: [16, 9],
quality: 0.5,
});
// console.log(image);
};
return (
<View>
<View></View>
<Button title='take picture' onPress={imagePickerHandler} />
</View>
);
};
export default ImagePicker;
1条答案
按热度按时间zrfyljdw1#
imagePickerHandler
语句中更改您的return语句。useEffect
,这会使事情变得容易得多。