Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACCESS_FINE_LOCATION not working

The following is my AndroidManifest.xml...

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="22" />

<application
  android:name=".BeaconApp"
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyBqhOHH31FYObdzoVW9TmQsv62TOP0LSLI"/>
</application>

As you can see I added the proper permissions necessary to get location info. However, when I run my app, I get a strange error...

Looks like the app doesn't have permission to access location.
Add the following line to your app's AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

throwLocationPermissionMissing
...etc

I already added this in my AndroidManifest.xml so why am I getting this error. I tried restarting Android Studio. I tried Wiping Data from emulator. I tried Gradle -> Clean. None of these helped. What is going on here?

Is it possible that my android emulator is blocking GPS or something?

like image 352
buydadip Avatar asked Dec 04 '16 03:12

buydadip


People also ask

What is the purpose of setting the user permission for Access_fine_location?

If your app needs to access the user's location, you must request permission by adding the relevant Android location permissions to your app. Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION . The permission you choose determines the accuracy of the location returned by the API.

How do I grant background location permissions in Android?

In order to enable background location access, users must set the Allow all the time option for your app's location permission on a settings page, as described in the guide on how to Request background location.

How do I request runtime permission on Android?

checkSelfPermission(String perm); It returns an integer value of PERMISSION_GRANTED or PERMISSION_DENIED. Note: If a user declines a permission that is critical in the app, then shouldShowRequestPermissionRationale(String permission); is used to describe the user the need for the permission.


1 Answers

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.

like image 64
ELITE Avatar answered Oct 11 '22 13:10

ELITE