-
Notifications
You must be signed in to change notification settings - Fork 4
Requesting Geo permissions for Android automatically
Davor Komušanac edited this page Dec 5, 2022
·
1 revision
Starting from 6.0.0 version you can use MobileMessaging plugin to request permissions for android automatically.
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 Example app
- Make sure that location permission is added to android configuration in
/android/app/src/main/AndroidManifest.xml
:
<manifest>
...
<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>
-
Per Google requirements geo disclosure dialog should be shown to the user before starting the process of asking permissions, on Example app it is shown on the application start, until the user do not accept it.
-
Setup rationale which will be displayed if it's required for asking geofencing permissions. It'll be displayed before showing settings screen with location permissions.
let androidGeoPermissionsRationaleOptions = {
title: "Update location settings",
message: "Allow application to access your location all the time to let it trigger geo notifications even when app is closed or not in use",
buttonNegative: "cancel",
buttonPositive: "settings"
};
- Call
mobileMessaging.requestAndroidPermissions
method with rationale, created at previous step. Example code shows how it's implemented in Example application, if geo Disclosure Dialog isn't accepted usual initialization of mobileMessaging will be called withgeofencingEnabled: true
in configuration.
if (!geoDisclosureDialogAccepted) {
// Initialize will be called with `geofencingEnabled: true`, user can give permissions later.
// Geofencing won't work until permissions are granted.
this.initMobileMessaging();
} else {
//Request geofencing permissions using mobileMessaging method, you can create your own implementation if provided isn't suite.
mobileMessaging.requestAndroidPermissions(androidGeoPermissionsRationale).then(granted => {
if (!granted) {
console.log('Required Geofencing permissions are not granted.');
}
this.initMobileMessaging();
})
}
...
configuration = {
applicationCode: 'your application code',
ios: {
notificationTypes: ['alert', 'badge', 'sound'],
},
geofencingEnabled: true,
};
initMobileMessaging() {
mobileMessaging.init(
this.configuration,
() => this.updateLogInfo('MobileMessaging started'),
(error) => this.updateLogInfo('MobileMessaging error: ' + error)
);
}
If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue.
- Library events
- Server errors
- User profile
- Messages and notifications management
- Geofencing
- Privacy settings
- In‐app chat
- WebRTC Calls and UI
- Migration guides