Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACCESS_FINE_LOCATION AndroidManifest Permissions Not Being Granted

Tags:

I am trying to utilize GPS in Android (2.2 and 2.3) but am getting the following error when I try to use the LocationManager object:

WARN/System.err(522): java.lang.SecurityException: Provider network requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission

I have researched the issue in other posts and they are typically due to issues with AndroidManifest.xml. However, mine appears to be fine:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.thedigitalsean.examples"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".GetLocation"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permisssion.INTERNET"></uses-permission>
</manifest>

Here is the offending line of code in my onCreate method in the GetLocation Activity, encased in a try/catch block:

    LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    final LocationListener locListener = new MyLocListener();

    try{
        locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
    }
    catch (SecurityException se){
        ((TextView)findViewById(R.id.infobox)).setText(se.toString());
        se.printStackTrace();
    }

This is the first app I have written where I need to request android permissions and have so far been unsuccessful in being granted any permissions whatsoever. Is there something I am missing in my manifest or perhaps in my eclipse configuration?

like image 334
thedigitalsean Avatar asked Jul 11 '11 20:07

thedigitalsean


2 Answers

You misspelled permission

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
like image 76
atraudes Avatar answered Oct 21 '22 07:10

atraudes


I was having the same problem and could not figure out what I was doing wrong. Turns out, the auto-complete for Android Studio was changing the text to either all caps or all lower case (depending on whether I typed in upper case or lower cast words before the auto-complete). The OS was not registering the name due to this issue and I would get the error regarding a missing permission. As stated above, ensure your permissions are labeled correctly:

Correct:

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

Incorrect:

<uses-permission android:name="ANDROID.PERMISSION.ACCESS_FINE_LOCATION" />

Incorrect:

<uses-permission android:name="android.permission.access_fine_location" />

Though this may seem trivial, its easy to overlook.

If there is some setting to make permissions non-case-sensitive, please add a comment with the instructions. Thank you!

like image 30
Slopes Avatar answered Oct 21 '22 06:10

Slopes