日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android手机拍摄权限,react-native 手机拍照权限

發布時間:2023/12/4 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android手机拍摄权限,react-native 手机拍照权限 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一步 :

在 android/app/src/main/AndroidManifest.xml

添加

然后運行項目在手機應用權限哪里查看

這是添加前的

這是添加后的

第二步調用

import React, {Component} from 'react';

import {

View,

Text,

Image,

StyleSheet,

Button,

Modal,

TouchableHighlight,

TouchableOpacity,

Dimensions

} from 'react-native';

import ImagePicker from 'react-native-image-picker';

// const Dimensions = require ('Dimensions') ;

export default class Jidan extends Component {

state={

avatarSource: {},

}

// 選擇圖片或相冊

onClickChoosePicture = () => {

const options = {

title: '',

cancelButtonTitle: '取消',

takePhotoButtonTitle: '拍照',

chooseFromLibraryButtonTitle: '選擇照片',

storageOptions: {

skipBackup: true,

path: 'images',

}

};

ImagePicker.showImagePicker(options, (response) => {

console.log('Response = ', response);

if (response.didCancel) {

console.log('User cancelled image picker');

} else if (response.error) {

console.log('ImagePicker Error: ', response.error);

} else if (response.customButton) {

console.log('User tapped custom button: ', response.customButton);

} else {

const source = {uri: response.uri};

this.setState({

avatarSource: source,

});

console.warn(this.state.avatarSource.uri);

}

});

}

async requestCarmeraPermission() {

try {

const granted = await PermissionsAndroid.request(

PermissionsAndroid.PERMISSIONS.CAMERA,

{

'title': 'Camera Permission',

'message': 'the project needs access to your camera ' +

'so you can take awesome pictures.'

}

)

if (granted === PermissionsAndroid.RESULTS.GRANTED) {

this.show("你已獲取了相機權限")

} else {

this.show("獲取相機失敗")

}

} catch (err) {

this.show(err.toString())

}

}

render() {

return (

onPress={this.requestCarmeraPermission.bind(this)}>

申請相機權限

this.onClickChoosePicture()}>選擇圖片

);

}

}

const styles = StyleSheet.create({

button_view: {

margin:4,

borderRadius: 4,

backgroundColor: '#8d4dfc',

alignItems: 'center',

},

button_text: {

padding: 6,

fontSize: 16,

fontWeight: '600'

},

container: {

flex: 1,

flexDirection: 'column',

justifyContent: 'center',

alignItems: 'center',

marginBottom:60,

},

textStyle:{

backgroundColor:'#66CCFF',

paddingHorizontal:50,

paddingVertical:10,

},

uploadAvatar:{

width: 150,

height: 150,

}

});

總結

以上是生活随笔為你收集整理的android手机拍摄权限,react-native 手机拍照权限的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。