Starting with SDK 23, you need / need to check the resolution before you look at the API functions. Here is an example of how to do this:
if (locationManager != null) { if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { locationManager.removeUpdates(GPSListener.this); } }
There is checkSelfPermission() , which should check if "you" (this application) have the correct permissions. There is also checkPermission() , which should check if the other process has the correct permissions.
Notes
- next to doing this runtime check, you still need to require the appropriate permissions in AndroidManifest.
- if your targetSdk is <23, you should use
ContextCompat.checkSelfPermission() instead (thanks JerryBrady)
Tim castelijns
source share