here is my AndroidMainfest.xml
enter code here
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
and here is my code
import React, { Component, useRef, PermissionsAndroid } from 'react';
import { View, StatusBar, TouchableOpacity, Image } from 'react-native';
import {RNCamera as Camera} from 'react-native-camera';
import styles from '../src/components/styles';
import PhotoCaptureIcon from '../assets/camera.png';
import CameraRoll from "@react-native-community/cameraroll";
const checkAndroidPermission = async () => {
try {
const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
await PermissionsAndroid.request(permission);
Promise.resolve();
}catch (error) {
Promise.reject(error);
}
};
export default class Application extends Component {
constructor(props) {
super();
this.camera = null;
}
takePicture =async () => {
if (Platform.OS === 'android'){
await checkAndroidPermission();
}
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
console.log(data.uri);
if (data) {
const result = await CameraRoll.save(data.uri);
console.log('????result', result);
}
}
}
render() {
return (
<View style={styles.container}>
<StatusBar animated hidden />
<Camera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
type={Camera.Constants.Type.back}
flashMode={Camera.Constants.FlashMode.off}
captureAudio={false}
/>
<View style={[styles.overlay, styles.bottomOverlay]}>
<TouchableOpacity style={styles.captureButton} onPress={this.takePicture}>
<Image source={PhotoCaptureIcon} />
</TouchableOpacity>
</View>
</View>
);
}
}
and error Possible Unhandled Promise Rejection (id: 5): Error: Permission denied promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2242:45 _callee$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:130062:75 tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:24919:23 invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25092:32 tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:24919:23 invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:24992:30 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25002:21 tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:26991:16 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27092:27 _callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30531:17 _callImmediatesPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30570:17 callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30787:33 __callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2736:35 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2522:34 __guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2719:15 flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2521:21 flushedQueue@[native code] invokeCallbackAndReturnFlushedQueue@[native code]