No permissions granted on Android emulator
Solution 1
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.
Solution 2
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
}
}
Marc
Updated on June 05, 2022Comments
-
Marc almost 2 years
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.xmlIf I remove all
<uses-permission>
tags from the manifest and go toSettings > Apps > TestApp
, it says No permissions requestedIf 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?
- IDE: Android Studio
- Virtual Device: Nexus_5_API_23
- OS: guest Ubuntu 14.04 running on host OS X Yosemite (VMWare Fusion)