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

前端 未结 6 1880
后悔当初
后悔当初 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:41

    This did not work for me

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

    I referred to https://facebook.github.io/react-native/docs/permissionsandroid.html#request and check() return a boolean

    const granted = await PermissionsAndroid.check( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION );
    
    if (granted) {
      console.log( "You can use the ACCESS_FINE_LOCATION" )
    } 
    else {
      console.log( "ACCESS_FINE_LOCATION permission denied" )
    }
    

提交回复
热议问题