react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Detect Android foreground service notification click

Open maxymczech opened this issue 2 years ago • 4 comments

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 ```

maxymczech avatar Jul 19 '23 12:07 maxymczech

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.

maxymczech avatar Jul 19 '23 15:07 maxymczech

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.

maxymczech avatar Jul 20 '23 14:07 maxymczech

I’ll see what can be done.

christocracy avatar Jul 20 '23 14:07 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 08 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 22 '24 01:05 github-actions[bot]