Get permission status when user has given permission to Runtime location access on Android

Asked

Viewed 30 times

0

I’m getting the location data using the LocationManager on Android and would like to know how I can catch the action only if the user allow the app accesses your location data.

For example, using the code below, I can pick up according to the positive permission of the user, I need before he accepts the permission to then work up

However, I need to take the precise data if the user has already allowed it or not, to work on this data regardless of whether he accepts it or not. It is possible?

@Override
protected void onResume() {
    super.onResume();
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
       //O que precisa fazer se a permissão for aceita.
    }
}

1 answer

1

There are libraries that can assist you in this task. This reduces the number of lines of code and makes your life easier and whoever uses your code later, if applicable.

My two favorites are: Permissionmanager and the Dexter

  • Thank you, brother. I think I’d better implement a library even to handle the exceptions to the permissions. But is there no way to get the stastus just the status if Runtime permissions have already been allowed or not? Valeuu!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.