transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.63k stars 425 forks source link

No Geofence event and permission on Galaxy 20 and Android emulator #1120

Closed jin-chong closed 3 years ago

jin-chong commented 4 years ago

Definitely I will purchase it for Android. But I should show it to the customer before purchase. Please help me.

Your Environment

async componentDidMount() { // Step 2: #configure: BackgroundGeolocation.ready( { locationAuthorizationRequest: 'Always', distanceFilter: 10, stopOnTerminate: false, startOnBoot: true, heartbeatInterval: 60, enableHeadless: true, // android foregroundService: true, // android notification: { title: 'My App', text: 'AAA', }, // << android debug: Platform.OS === 'android', // todo: how to enable disable it by compile option? logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, // todo: how to enable disable it by compile option?

  },
  (state) => {
    this.bgServiceReady = true;
    console.log('- Configure success: ', state);
    if (!state.enabled) {
      BackgroundGeolocation.start();
    }
  },

} ... }


## Expected Behavior
On Galaxy 20,
1. It should detect and send Geofense event, but it doesn't.  It works on emulator.  **At Galaxy 20, I ran Mock GPS app for test.  If it is caused by this GPS app, please advise me the way of testing from real phone**
2. When it does not have enough Permission, it does not ask Permission anymore when it starts again.  It works on iOS simulator
3.  There should be a foreground notification banner but I cannot find the foreground notification banner.

On Android emulator, 
1. When it does not have enough Permission, it does not ask Permission anymore when it starts again.  It works on iOS simulator

## Actual Behavior
<!--- Tell us what happens instead -->
On Galaxy 20,
1. It should detect and send Geofense event, but it doesn't on foreground or background.   It works on emulator.
2. When it does not have enough Permission, it does not ask Permission anymore when it starts again.  It works on iOS simulator
3.  There should be a foreground notification banner but I cannot find the foreground notification banner.

On Android emulator, 
1. When it does not have enough Permission, it does not ask Permission anymore when it starts again.  It works on iOS simulator

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1. npx react-native run-android .
2. then run it. and switch between foreground and background.
3. At Galaxy 20, I ran Mock GPS app for test.  If it is caused by this GPS app, please advise me the way of testing from real phone
4.

## Context
<!--- What were you trying to do? -->
I want to use Geofense function on foreground and background, then restart after reboot, on Android and iOS both.

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details><summary>Logs</summary>

``` <!-- Syntax highlighting:  DO NOT REMOVE -->
because of size I put the link to the file [logcat link](https://1drv.ms/t/s!AjdU6cu7sA3BuwEOiihHEp4HTunP?e=7u1aIc)

christocracy commented 4 years ago

Geofence events are flaky with mocked location.

It’s a well-known problem, google it: “android geofence mock location”.

Best way to test geofences is on real device in real world testing.

jin-chong commented 4 years ago

Hi @christocracy Thanks for your reply. I don't know, but it shows me inconsistent behaviour on android. It stops working on background. and I cannot see foreground notification bar. My setup is same with original post. I records screen with app operation and logs. Could you please watch it and give me some advice? I really wanna use it, but I'm so desperate. video link - https://1drv.ms/v/s!AjdU6cu7sA3BuwYPNeJnAw_TFNFK?e=mF3dhl

christocracy commented 4 years ago

Are you observing the plugin logs? See wiki Debugging.

jin-chong commented 4 years ago

Yes. you can watch I'm collecting by adb logcat from the above screen record. As you can watch from screen record, plugin logs does not show any geofence change when application runs on background.

jin-chong commented 4 years ago

Ok, @christocracy . I figured out what happens.

On iOS, BackgroundGeolocation.startGeofences() is working on background as expected. But on Android, startGeofences() does not work on background.

I think on Background Android, Location event needs for Geofence event.

To trigger geofence event on background Android,

  1. If I called startGeofences(), I should call getCurrentPosition at heartbeat event (BackgroundGeolocationHeadlessTask or BackgroundGeolocation.onHeartbeat depending on App state).
  2. Or I should call BackgroundGeolocation.start()

Could you please confirm it? and any plan to get it fixed?

christocracy commented 4 years ago

If I called startGeofences(), I should call getCurrentPosition at heartbeat event

No

Or I should call BackgroundGeolocation.start()

No.

jin-chong commented 4 years ago

Hi @christocracy , I've tested it with Config.geofenceModeHighAccuracy true/false both. same results. On Android emulator, startGeofences() does not fire geofence event on background. However when I call getCurrentPosition at heartbeat event, App receives geofence event following location event.

the below is my configuration and then I run startGeofences(). And I uploaded the screen record. please watch it. https://1drv.ms/u/s!AjdU6cu7sA3Buwd0PpBbpBfEBXUU?e=9WZ6RQ


      {
        locationAuthorizationRequest: 'Always', // Geofence monitoring requires the user authorize locationAuthorizationRequest Always
        distanceFilter: 10,
        stopOnTerminate: false,
        startOnBoot: true,
        heartbeatInterval: 60,
        // >> for iOS
        preventSuspend: true, // iOs
          locationAuthorizationAlert: {
            titleWhenNotEnabled: "location-services not enabled",
            titleWhenOff: "location-services OFF",
            instructions: "You must enable 'Always' in location-services",
            cancelButton: "Cancel",
            settingsButton: "Settings"
          },
        // << for iOS
        // >> android
        enableHeadless: true, // android
        foregroundService: true, // android
        notification: {
          title: 'App  active',
          text: 'Hello.',
          // sticky: true,
          // priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_HIGH,
        },
        // << android
        debug: Platform.OS === 'android', // todo:  how to enable disable it by compile option?
        logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, // todo:  how to enable disable it by compile option?
        geofenceInitialTriggerEntry: true,
        geofenceModeHighAccuracy: true,
      },```

Thanks.
christocracy commented 4 years ago

You can’t reliably test geofences in emulator.

You need to do real world testing on a real device.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] commented 3 years ago

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.