react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Detect Android foreground service notification click
Your Environment
- Plugin version: 4.10.0
- Platform: Android
- OS version: 11
- Device manufacturer / model: Xiaomi Mi A3
- React Native version (
react-native -v): 0.64.2 - Plugin config
{
backgroundPermissionRationale: {
title: i18n.t('huntingTrails.backgroundLocation.locationAlertTitle'),
message: i18n.t('huntingTrails.backgroundLocation.locationAlertText'),
positiveAction: i18n.t('huntingTrails.backgroundLocation.yes'),
negativeAction: i18n.t('huntingTrails.backgroundLocation.no'),
},
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 30,
fastestLocationUpdateInterval: 5000,
foregroundService: true,
httpRootProperty: '_json',
httpTimeout: 20 * 1000,
locationAuthorizationRequest: 'Always',
locationUpdateInterval: __DEV__ ? 10000 : 20000,
logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
notification: {
color: Colors.primary,
text: i18n.t('huntingTrails.backgroundLocation.notificationText'),
sticky: true,
title: i18n.t('huntingTrails.backgroundLocation.notificationTitle'),
priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_HIGH,
},
startOnBoot: false,
stopOnTerminate: false,
stopTimeout: 1,
}
Expected Behavior
I need a way to detect if the user clicked the Android foreground service notification, and redirect him to a specific screen in the application.
Actual Behavior
The documentation for the plugin describes onNotificationAction listener to detect clicks on custom layout buttons, but no way to detect the click on the notification itself.
Context
See "Expected behavior"
Debug logs
Logs
``` N/A ```
P. S. Also, on this page it says that XML layout file will be created in the folder app/res/layouts, but my Android Studio created it in the folder app/res/layout.
P. P. S. I came close to solving my issue by using a custom layout and making the whole of it clickable, by adding android:clickable="true" and android:id attribute to the top-level <LinearLayout> element. This way, the entire notification is treated as a large button, and a click event is forwarded to the plugin and can be handled. Unfortunately, this has a big downside: after the click, the Android notification panel remains open.
I’ll see what can be done.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.