0

My app is using target-release version 22. I've mentioned FINE_LOCATION permission in manifest file. When I'm running my app on android 6.0.1, it's working fine for my map-view where I'm showing current location. But problem I'm getting when user "Deny" permission from app setting then app start crashing due to Permission-exception.

When I'm using below code

if ((ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) 
                    ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION_PERMISSION);
            }

But this code always returning PackageManager.PERMISSION_GRANTED. Can someone help to resolve this issue?

I've already gone through these links - Understanding the Android 6 permission method Request Permission at Runtime for Android Marshmallow 6.0

Community
  • 1
  • 1
Pankaj
  • 833
  • 12
  • 35

1 Answers1

-1

It's resolved by using PermissionChecker. PermissinChecker return status of Granted/Deny for even build version less than 23

if(Build.VERSION.SDK_INT >= 23){
    int permissionStatus = PermissionChecker.checkSelfPermission(context, permission);
    if(permissionStatus != PackageManager.PERMISSION_GRANTED){
        ActivityCompat.requestPermissions(context, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 101);
        return false;
    }
}
Pankaj
  • 833
  • 12
  • 35