ACCESS_FINE_LOCATION not working

一曲冷凌霜 提交于 2019-12-04 05:56:50
ELITE

Have you tried asking permissions at runtime..

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
    Manifest.permission.ACCESS_FINE_LOCATION);
if(permissionCheck != PackageManager.PERMISSION_GRANTED) {
    // ask permissions here using below code
    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_CODE);
}

You can check details on this site Requesting Permissions at Run Time

This is the way you ask user to grant permission at runtime after android 6.0

You can check Android 6.0 Permission Error answer also.

Hope it'll help you.

what you need is the runtime permission. technically speaking, since os 6, the manifest permission doesnt mean anything.

google "android runtime gps permission" and you'll get tons of answers on what to do and why.

With React-Native you have to use PermissionsAndroid to get permissions on Android 6.0 (or later) devices..

Add these lines to your files

import { PermissionsAndroid } from 'react-native';

async function requestLocationPermission() {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      {
        'title': 'Location Permission',
        'message': 'This app needs access to your location',
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the location")
    } else {
      console.log("Location permission denied")
    }
  } catch (err) {
    console.warn(err)
  }
}

then call requestLocationPermission() before using the location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!