-
Notifications
You must be signed in to change notification settings - Fork 2
Requesting Geo permissions automaticaly
Geofencing feature is DEPRECATED and not supported from SDK version 7.0.0 onwards.
Starting from 3.0.0 version process of requesting permissions for Geofencing feature could be easier. Mobile Messaging SDK could request permissions automatically for you.
Following permissions needs to be requested (Requesting Location Permissions):
- For API > 29 (Android > 10),
ACCESS_FINE_LOCATION
andACCESS_COARSE_LOCATION
needs to be requested and if granted then alsoACCESS_BACKGROUND_LOCATION
- For API 29 (Android 10)
ACCESS_FINE_LOCATION
andACCESS_COARSE_LOCATION
needs to be requested - For API < 29 (Android < 10) only
ACCESS_FINE_LOCATION
is required.
Example of requesting permissions on Android 12 |
![]() |
Full implementation can be checked in Geofencing Example
- Provide activity or fragment which will be used for requesting permissions.
Call
setContextForRequestingPermissions
method before your fragment or activity is created, for example insideonCreate
call of the activity. Because this method will call [registerForActivityResult
] method which is safe to call before your fragment or activity is created.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MobileGeo.getInstance(this).setContextForRequestingPermissions(this);
...
}
- Call
activateGeofencingWithAutomaticPermissionsRequest
when you want to start process of requesting the permissions. when all required permissions are granted, geofencing will be activated.
Do not call it until the fragment or activity's Lifecycle has reached CREATED
Boolean parametershouldShowPermissionsNotGrantedDialogIfShownOnce
is indicating whether you want to repeat displaying "Permissions not granted" dialog constantly or show it just once:
- If you are asking for permissions by button tap, better to return true, so user will be informed why an action can't be done, if the user didn't grant the permissions.
- If you are asking for permissions on the application start, better to return false not to disturb the user constantly.
MobileGeo.getInstance(MainActivity.this).activateGeofencingWithAutomaticPermissionsRequest(false);
- "Update location settings" dialog's title and message can be customized by changing following strings in your resources:
<string name="geofencing_update_location_settings_title">Custom title</string>
<string name="geofencing_update_location_settings_message">Custom message</string>
- "Permissions not granted" dialog's title and message can be customized by changing following strings in your resources:
<string name="geofencing_permissions_not_granted_title">Custom title</string>
<string name="geofencing_permissions_not_granted_message">Custom message</string>
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
Geofencing APIDEPRECATED- Android Manifest components
- Privacy settings
- In-app chat