Search code examples
androidkotlinlocation

How to request information from the application whether the user has allowed access to geolocation


In my application, the user allows (or not) the application access to geolocation data. It is very important for me to get information whether he did it or not. Ideally, if there is some code that would return the result in the form of Boolean, because PackageManager.PERMISSION_GRANTED returns Int and I do not know how to use it. Has anyone solved this problem? I will be very glad to help.


Solution

  • if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_MEDIA_LOCATION) == PERMISSION_GRANTED) {
       //User have granted the permission
    }
    

    You can check permissions like that