I wrote a simple Hello World app to debug some permissions problem I'm having.
The problem is that my app can't obtain permissions to use anything. Yes, I'm using
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and yes I put that tag right under <manifest>
in AndroidManifest.xml
If I remove all <uses-permission>
tags from the manifest and go to Settings > Apps > TestApp
, it says No permissions requested
If I put the tags back in, it says No permissions granted
If I debug on an actual device, it says the permissions are there so it looks like this problem is only occurring on the emulator! However, it also works when I run the android-play-location/LocationUpdates
project from developer.android.com using the same emulator so maybe there's something wrong with my project setup.
Any ideas?
If I put the tags back in, it says No permissions granted
That is because you are testing on Android 6.0, and your targetSdkVersion
is set to 23.
If I debug on an actual device, it says the permissions are there so it looks like this problem is only occurring on the emulator!
No, it is occurring only on Android 6.0+.
However, it also works when I run the android-play-location/LocationUpdates project from developer.android.com using the same emulator so maybe there's something wrong with my project setup.
That project probably has a targetSdkVersion
below 23.
ACCESS_FINE_LOCATION
is governed by the Android 6.0 runtime permission system . Either update your app to use that system, or drop your targetSdkVersion
below 23 until you are ready to do so.
just request location permission if you are running on M
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && getActivity().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION);
}else{
//Do things as usual
}
wait for a result in
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] result){
super.onRequestPermissionsResult(requestCode, permissions, result);
if(requestCode == LOCATION_PERMISSION && result[0] == PackageManager.PERMISSION_GRANTED){
//do things as usual init map or something else when location permission is granted
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.