反应式本机相机无法在Android中进行第二次调用。在第二次调用时,应用程序崩溃。 我在用 本机:0.56.0 react-native-camera:1.6.4 使用最新版本的react-native-camera时是相同的。 我无法将react-native更新为最新版本,因为我有另一个与最新版本不兼容的软件包,并且 在模拟器上可以正常工作,只有实际设备存在问题
我的相机屏幕
class CameraScreen extends Component {
constructor(props) {
super(props);
this.state = {
boltIconIsPressed: false,
};
}
renderError() {
Alert.alert(
'Error',
'Something went wrong, Try again!',
[
{ text: 'Ok', style: 'cancel' },
],
);
this.props.navigation.goBack();
}
render() {
if (this.props.isFocused) {
return (
<View style={styles.container}>
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
type={RNCamera.Constants.Type.back}
flashMode={this.state.boltIconIsPressed ? RNCamera.Constants.FlashMode.off : RNCamera.Constants.FlashMode.on}
onMountError={this.renderError.bind(this)}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
/>
<View
style={{ flex: 0,
flexDirection: 'row',
justifyContent: 'center',
backgroundColor: 'transparent' }}
>
<Button
outline
rounded
style={styles.capture}
onPress={() => this.props.navigation.navigate('gallery')}
>
<Icon
type='Entypo'
name='image'
style={{ color: '#862d59', }}
/>
</Button>
<Button
outline
rounded
onPress={this.takePicture.bind(this)}
style={styles.capture}
>
<Icon
type='SimpleLineIcons'
name='camera'
style={{ color: '#862d59', }}
/>
</Button>
<Button
outline
rounded
style={styles.capture}
onPress={() => this.setState({ boltIconIsPressed:
!this.state.boltIconIsPressed })}
>
<Icon
type='MaterialCommunityIcons'
name={this.state.boltIconIsPressed ? "flash-off" : "flash"}
style={{ color: '#862d59', }}
/>
</Button>
</View>
</View>
);
}
return (
<View />
);
}
takePicture = async function () {
let data = null;
if (this.camera) {
const options = {
width: 1800,
base64: true,
};
console.log(data);
data = await this.camera.takePictureAsync(options);
this.props.navigation.navigate('uploadscreen', {
image: data,
});
}
};
}
export default withNavigationFocus(CameraScreen);
预先感谢
答案 0 :(得分:0)
出现此错误是因为我没有存储设备来保存拍摄的图像。要使其正常运行,请将其添加到AndroidManifest.xml文件中
android:largeHeap =“ true”