my android manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.regnav.stilla" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I try to use the permission which is in the Android Manifest like this:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
Location location = locationManager.getLastKnownLocation(provider);
It will tell me that I need to do a permission check like so:
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// public void requestPermissions(@NonNull String[] permissions, int requestCode)
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.
return;
}
I think this is strange as my android manifest already gives me permission to do this.. Am I doing something wrong?
I am editting the Android manifest in location:
Stilla/app/src/main/AndroidManifest.xml
What Am I doing wrong?
If you are on Android 6.0, checking whether you have a specific permission at any given point in the lifecycle of the app is mandatory. It is so because the user can revoke any single permission anytime he feels so and your app is NOT notified about this revoken permission.
Hence, before using any API which needs a permission, you should check whether you have by using the snippet you have posted. This is true even if you have that permission in your manifest. Have a look at the developer article
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments