I have android application and we have recently shifted to API level 26 from 22.
I have cheked if the app has one of the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
One issue that I found and not able to solve is that it gives an exception like "java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission"
My Android manifest file has:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Also I got this kind of exception:
Process: edu.syr.ischool.orange.indoormap3, PID: 12666
java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.readException(Parcel.java:2005)
at android.os.Parcel.readException(Parcel.java:1951)
at android.location.ILocationManager$Stub$Proxy.getLastLocation(ILocationManager.java:802)
at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1220)
at utils.CheckinUtils.checkLocation(CheckinUtils.java:100)
at utils.CheckinUtils.resume(CheckinUtils.java:247)
Also my checkinUtil --> checkLocation Method
if (ActivityCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager = (LocationManager) activity.getSystemService(serviceString);
Location lastKnow = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
I have checked for permission of either one of them as documented on https://developer.android.com/reference/android/location/LocationManager#getLastKnownLocation(java.lang.String)
Still, It gives an exception for ACCESS_FINE_LOCATION but as it passes the if condition and gives the security exception so it should have the ACCESS_COARSE_LOCATION permission. Then Why the application is crashing?