1

This is my manifest file:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.steff.barometer" >

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            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>

</manifest>

So I run the app from android studio and get:

java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.

I already removed the app completely from my device, also, cleaned my project and tried to re-deploy, nothing works...

I am using a Nexus 5 with Android 6 as a test device, Android project SDK is set to 23

Mazzy
  • 1,901
  • 2
  • 16
  • 36

2 Answers2

2

Beginning with Android 6.0 (Marshmallow, API level 23), applications must ask the user for permissions at runtime.

You still need to request the permission in the manifest as well, but the permissions are no longer automatically granted when the application is installed.

To learn more about runtime permissions, including code samples, check out the Requesting Permissions at Run Time documentation.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
2

I think you are using marshmellow(API 23) for this you need to request for run time permissions for access_fine_location permission. Do it in the following way:

context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED &&
                context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED)

  @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                           int[] grantResults) {
        if (requestCode == MY_PERMISSIONS_REQUEST_CODE) {
            Log.v("Toadways", "onRequestPermissionsResult");
            isPermissionRequest = false;
         //your code
}

for more info check the following link:

http://developer.android.com/training/permissions/requesting.html

Hope this helps.

Kiran
  • 96
  • 2
  • 10