Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback onHeartbeat never fires #177

Closed
draganjovanovic1 opened this issue Jan 15, 2020 · 8 comments
Closed

Callback onHeartbeat never fires #177

draganjovanovic1 opened this issue Jan 15, 2020 · 8 comments

Comments

@draganjovanovic1
Copy link

Callback onHeartbeat never fires.

Your Environment

  • Plugin version: 1.5.0
  • Platform: Android
  • OS version: 10
  • Device manufacturer / model: Essential Phone PH-1
  • Flutter info (flutter doctor):
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.13.10-pre.65, on Mac OS X 10.15.2 19C57, locale en-RS)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.41.1)
[✓] Connected device (1 available)

• No issues found!
  • Plugin config:
  static void initialize({@required TrackingBloc trackingBloc}) {
    bg.BackgroundGeolocation.onLocation((location) {
      log.FLog.info(text: 'Foreground onLocation fired: $location');
      trackingBloc.add(LocationChanged(location: location));
    },
        (bg.LocationError err) => log.FLog.error(
            text: 'Location error occurred: ${err.message}, ${err.code}'));

    bg.BackgroundGeolocation.onMotionChange((location) {
      log.FLog.info(text: 'Foreground onMotionChange fired: $location');
      trackingBloc.add(LocationChanged(location: location));
    });

    bg.BackgroundGeolocation.onHeartbeat((bg.HeartbeatEvent event) {
      log.FLog.info(text: 'Foreground onHeartbeat fired: $event');
      onHeartbeatCallback(event,
          (location) => trackingBloc.add(LocationChanged(location: location)));
    });

    bg.BackgroundGeolocation.ready(bg.Config(
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
        distanceFilter: 10.0,
        locationUpdateInterval: 30 * 1000,
        maxRecordsToPersist: 50,
        disableElasticity: false,
        enableHeadless: true,
        foregroundService: true,
        stopOnTerminate: false,
        startOnBoot: true,
        preventSuspend: true,
        autoSync: false,
        maxDaysToPersist: 5,
        allowIdenticalLocations: false,
        heartbeatInterval: 60,
        debug: true,
        logLevel: bg.Config.LOG_LEVEL_VERBOSE,
        notification:
            bg.Notification(smallIcon: 'drawable/ic_stat_notification_icon')));

    trackingBloc.listen((x) async {
      if (x.isTracking()) {
        await TrackingService.start();
      } else {
        await TrackingService.stop();
      }
    });

Expected Behavior

onHeartbeat callback should fire.

Actual Behavior

onHeartbeat callback never fires.

Context

I am trying to force app to report to the server once in 5 minutes even if it is not moving. Heartbeat event should be the one I need since it should fire in foreground as well as in the headless mode according to my understanding of the docs.

I see periodically HeartbeatService$a run and HeartbeatService onDestroy logged but my callback is not being fired.

Debug logs

Logs
D/TSLocationManager(15548): [c.t.l.s.HeartbeatService$a run] ❤️
D/TSLocationManager(15548): [c.t.l.service.HeartbeatService onDestroy] onDestroy
V/MediaPlayer(15548): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(15548): cleanDrmObj: mDrmObj=null mDrmSessionId=null
W/MediaPlayer(15548): mediaplayer went away with unhandled events
@draganjovanovic1
Copy link
Author

Forgot to add part of the code where I start / stop tracking.

  static Future start() async {
    bg.State state = await bg.BackgroundGeolocation.state;

    if (!state.enabled) {
      log.FLog.debug(text: 'Starting location service...');
      await bg.BackgroundGeolocation.start();
      log.FLog.debug(text: 'Location service started...');
    }
  }

  static Future stop() async {
    bg.State state = await bg.BackgroundGeolocation.state;

    if (state.enabled) {
      log.FLog.debug(text: 'Stopping location service...');
      await bg.BackgroundGeolocation.stop();
      await bg.BackgroundGeolocation.removeListeners();
      log.FLog.debug(text: 'Location service stopped...');
    }
  }

Location tracking works like a charm, all good. Other callbacks onLocation and onMotionChange are being fired all the time.

@christocracy
Copy link
Member

Why do you await bg.BackgroundGeolocation.removeListeners();?

This is like disconnecting your speaker wires when you turn off your stereo. This is probably your problem.

When you call #stop, no events will be emitted so it's likely pointless to removeListeners, unless you're taking care to re-add them (but even then, it's not necessary to #removeListeners).

@draganjovanovic1
Copy link
Author

Hmm. Good catch. I was removing listener but not re-attaching them on start but on initialize only. It may be the cause of the issue... Will retest tomorrow and post results. Thanks.

@christocracy
Copy link
Member

Just don’t removeListeners.

@draganjovanovic1
Copy link
Author

Yep. Will try. It is very old line... I refactored the rest but it was left there somehow. And the more you look the less you see as usual. Thanks once again. Will get back to you with results.

@draganjovanovic1
Copy link
Author

BTW, not to open new issue. I have a problem with notification icon. It works normally on test device with flutter run but when I release the app it is not there, only white square. Any ideas?

@christocracy
Copy link
Member

No idea about icon. Likely something on your end.

@draganjovanovic1
Copy link
Author

It seems that removing removeListeners helped. Quickly tried it and callback is firing. Will test more tomorrow and reopen if needed. Closing now.

Would you mind checking the icon issue. Should I open new issue?

My quick guess is that release configuration is not good but I am definitely not an expert in gradle things. Here is my release build configuration:

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            useProguard true
            proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro"
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants