android手机拍摄权限,react-native 手机拍照权限
第一步 :
在 android/app/src/main/AndroidManifest.xml
添加
然后運行項目在手機應用權(quán)限哪里查看
這是添加前的
這是添加后的
第二步調(diào)用
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("你已獲取了相機權(quán)限")
} else {
this.show("獲取相機失敗")
}
} catch (err) {
this.show(err.toString())
}
}
render() {
return (
onPress={this.requestCarmeraPermission.bind(this)}>
申請相機權(quán)限
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,
}
});
總結(jié)
以上是生活随笔為你收集整理的android手机拍摄权限,react-native 手机拍照权限的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何使用快捷键快速保存网络图片
- 下一篇: 《骑士经理升级版》上手指南