How do I request permission for Android Device Location in React Native at run-time?

前端 未结 6 1873
后悔当初
后悔当初 2020-12-09 15:47

I have been trying to use React Native \'s GeoLocalisation for an Android App. The poorly documentated module is found here https://facebook.github.io/react-native/docs/geol

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 16:18

    in Manifest

     
        
    
    

    more details

    import {PermissionsAndroid} from 'react-native';
    
    async function requestCameraPermission() {
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.CAMERA,
          {
            title: 'Cool Photo App Camera Permission',
            message:
              'Cool Photo App needs access to your camera ' +
              'so you can take awesome pictures.',
            buttonNeutral: 'Ask Me Later',
            buttonNegative: 'Cancel',
            buttonPositive: 'OK',
          },
        );
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          console.log('You can use the camera');
        } else {
          console.log('Camera permission denied');
        }
      } catch (err) {
        console.warn(err);
      }
    }
    
    export default class AlertDetails extends Component{
    
        async componentDidMount() {
            await request_storage_runtime_permission()
        }
    }
    

提交回复
热议问题