react-native携帯電話の写真撮影権限
3245 ワード
ステップ1:
android/ap/src/main/Android Manifest.xmlに追加します.
そして、実行項目は携帯電話のアプリケーションの権限でどこで確認しますか?これは追加されたものです.
第二ステップはimport Reactを呼び出します.import{
//const Dimensions=require('Dimensions')export default class Jidan extens Component{
android/ap/src/main/Android Manifest.xmlに追加します.
そして、実行項目は携帯電話のアプリケーションの権限でどこで確認しますか?これは追加されたものです.
第二ステップはimport Reactを呼び出します.import{
View,
Text,
Image,
StyleSheet,
Button,
Modal,
TouchableHighlight,
TouchableOpacity,
Dimensions
from'react-native';import ImagePicker from'react-native-mage-picker'//const Dimensions=require('Dimensions')export default class Jidan extens 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 (
this.onClickChoosePicture()}>
);
}
}const style=Steyle Sheet.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,
}
}