-
Notifications
You must be signed in to change notification settings - Fork 17
Requesting Geo permissions automaticaly
Geofencing feature is DEPRECATED and not supported from SDK version 13.0.3 onwards.
Starting from 6.1.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 callregisterForActivityResult
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, it's per google recommendation for calling
ActivityResultLauncher
)
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);
Google is requiring displaying of prominent disclosure dialog, before asking for geo permissions, you'll need to implement it by yourself.
- "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>
This Dialog appears per google requirements before asking for "ACCESS_BACKGROUND_LOCATION" permission, for Android versions > 10
If you have any questions or suggestions, feel free to send an email to [email protected] or create an issue.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
Geofencing API- DEPRECATED- Android Manifest components
- Privacy settings
- In-app chat
- Infobip RTC calls and UI
- Backup rules