Android Location permission

How to request Android location permission

  1. Location on Android
  2. Request Location Permissions

To protect user privacy, apps that use location services must request location permissions. Check the Android Documentation about building location-aware apps for more details.

Location on Android

Android Location management provide users with a strong control and transparency over location data usages. Recent changes introduced dedicated permissions for foreground and background location.

Each permission has a combination of the following characteristics:

The Woosmap Geofencing SDK requires both accuracy permissions which are automatically added in the manifest along with the INTERNET, ACCESS_NETWORK_STATE, and RECEIVE_BOOT_COMPLETED. For Geofencing events capabilities you’ll also need to ask for the ACCESS_BACKGROUND_LOCATION permission:

xml
        
<manifest>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
</manifest> 

    

Request Location Permissions

Permission needs to be granted by the user at runtime. Before trying accessing the users’ location from the background, ensure the user consent for required permission. You can do this by checking the ACCESS_BACKGROUND_LOCATION permission. Here is a sample to request permission:

java
        private void requestPermissions() {  
     boolean shouldProvideRationale =  
            ActivityCompat.shouldShowRequestPermissionRationale(this,  
                    Manifest.permission.ACCESS_FINE_LOCATION);  
  
    // Provide an additional rationale to the user. This would happen if the user denied the  
    // request previously, but didn't check the "Don't ask again" checkbox.  
    if (shouldProvideRationale) {  
        // Displaying permission rationale to provide additional context.  
        ActivityCompat.requestPermissions(MainActivity.this,  
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION},  
                REQUEST_PERMISSIONS_REQUEST_CODE);  
    } else {  
        // Requesting permission
        ActivityCompat.requestPermissions(MainActivity.this,  
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION,  Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION},  
                REQUEST_PERMISSIONS_REQUEST_CODE);  
    }  
} 

    
Was this article helpful?
Have more questions? Submit a request