Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

How to access camera in react-native i can't save picture in my phone storage

$
0
0

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 errorPossible Unhandled Promise Rejection (id: 5):Error: Permission deniedpromiseMethodWrapper@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:75tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:24919:23invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25092:32tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:24919:23invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:24992:30http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25002:21tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:26991:16http://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:17callImmediates@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:35http://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:15flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2521:21flushedQueue@[native code]invokeCallbackAndReturnFlushedQueue@[native code]


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>