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

How to update location to my server after every 30 min automatically in kill state #84

Closed
ADARSHAGNIHOTRI opened this issue Jun 23, 2019 · 22 comments

Comments

@ADARSHAGNIHOTRI
Copy link


I want to send my location to my server after every 30 min automatically in kill state.


Your Environment mac

  • Plugin version:1.0.9
  • Platform: iOS and Android
  • OS version:12.2
  • Device manufacturer / model:
  • Flutter info (flutter doctor):
  • Plugin config:
PASTE_YOUR_CODE_HERE

bg.BackgroundGeolocation.getCurrentPosition(

    ). then((bg.Location location) {
      widget.store.dispatch(new UpdateCurrentLocationAction(WrappLocation.fromLocation(location)));   updateLocation(location.coords.latitude, location.coords.longitude);//(my api to send loc to server)
      // Fluttertoast.showToast( msg: 'LOCATION UPDATING -$location');
    }).catchError((error) {
      print('[getCurrentPosition] ERROR: $error');
    });

Expected Behavior

there should be a reasonable interval for which it execute in forground, backgound and kill state.

Actual Behavior

Dont have any interval for execution neither i got anything to control its execution.

Steps to Reproduce

Context

Debug logs

Logs
PASTE_YOUR_LOGS_HERE
@christocracy
Copy link
Member

christocracy commented Jun 23, 2019

You should implement flutter_background_fetch, already included as a dependency. Execute BackgroundGeolocation.getCurrentPosition in the fetch-callback.

@ADARSHAGNIHOTRI
Copy link
Author

ADARSHAGNIHOTRI commented Jun 24, 2019

I have done this but still didn't get anything worthy------>>>>>

  BackgroundFetch.configure(BackgroundFetchConfig(
          minimumFetchInterval: 15,
          startOnBoot: true,
          stopOnTerminate: false,
          enableHeadless: true
      ), () async {
        print('[BackgroundFetch] received event');
        print('eeee');
        bg.BackgroundGeolocation.getCurrentPosition(samples: 1).then((bg.Location location){
          widget.store.dispatch(new UpdateCurrentLocationAction(WrappLocation.fromLocation(location)));
          updateLocation(location.coords.latitude, location.coords.longitude);
        });
        BackgroundFetch.finish();
      });


void backgroundFetchHeadlessTask() async {
  print('[BackgroundFetch] Headless event received.');
  bg.BackgroundGeolocation.getCurrentPosition().then((bg.Location location){
    updateLocation(location.coords.latitude, location.coords.longitude);
    print('background fetch succesful');

  });
  BackgroundFetch.finish();
}

void main() {
  final store = new Store<GlobalAppStore>(appStateReducer, initialState: new GlobalAppStore(new Profile(), null, new List<TefillinWrapp>(), null, null, null));
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();


  //LocationPicker.initApiKey(globals.GOOGLE_MAPS_API_KEY);
  runApp(new TefillinWrappStore(store: store, firebaseMessaging: _firebaseMessaging,));
  BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);

}

@ADARSHAGNIHOTRI
Copy link
Author

my app stop working after killing my app after some time.

@christocracy
Copy link
Member

See http://dontkillmyapp.com

@ADARSHAGNIHOTRI
Copy link
Author

So my code is ok or not to fetch location in kill state?

@christocracy
Copy link
Member

So my code is ok

Yes.

@ADARSHAGNIHOTRI
Copy link
Author

Is it because i am using debug mode?

@christocracy
Copy link
Member

However, you should await bg.BackgroundGeolocation.getCurrentPosition() before calling bg.BackgroundFetch.finish().

@christocracy
Copy link
Member

Is it because i am using debug mode?

No

@ADARSHAGNIHOTRI
Copy link
Author

Is there any other method to solve my problem?(updaing location in kill state with some interval)
any link for solution please suggest me.

@christocracy
Copy link
Member

Is there any other method to solve my problem?

No. I field-test daily on 11 Android devices running untouched for weeks. I have no such problem except on my Huawei P20, which is the vendor's fault.

Your problem is likely related to the OS vendor (which you chose to ignore providing in the issue template.)

http://dontkillmyapp.com

@ADARSHAGNIHOTRI
Copy link
Author

It is samsung s6

@christocracy
Copy link
Member

And you're simulating background fetch events, as directed in the background_fetch README?

@ADARSHAGNIHOTRI
Copy link
Author

I have added Application.java file according to background geolocation plugin which is differ to background fetch android setup.So does it effect the functionality?

@ADARSHAGNIHOTRI
Copy link
Author

And you're simulating background fetch events, as directed in the background_fetch README?

Is it necessary?

@christocracy
Copy link
Member

If you want to be an efficient developer and test the functionality in seconds instead of waiting 15 minutes, yes.

@ADARSHAGNIHOTRI
Copy link
Author

ADARSHAGNIHOTRI commented Jun 25, 2019

I have added Application.java file according to background geolocation plugin which is differ to background fetch android setup.So does it effect the functionality?

What about this sir?
I this Application.java should be modified with "import com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin;"
and " BackgroundFetchPlugin.setPluginRegistrant(this);"
should be added.

@ADARSHAGNIHOTRI
Copy link
Author

If you want to be an efficient developer and test the functionality in seconds instead of waiting 15 minutes, yes.

Ok sir, Point to be noted. Thankyou for advice.

@ADARSHAGNIHOTRI
Copy link
Author

Still not working Don't know what to do now?

@ADARSHAGNIHOTRI
Copy link
Author

When i run this command in kill state then this appears----->>>

ADARSHs-Mac-mini:platform-tools adarshagnihotri$ ./adb shell cmd jobscheduler run -f com.lightuptheworld.tefillinwrap 999
Could not find job 999 in package com.lightuptheworld.tefillinwrap / user 0

@ADARSHAGNIHOTRI
Copy link
Author

My Application.java file---->>>>
package com.lightuptheworld.tefillinwrap;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;

import com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin;
import com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin;

public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
@OverRide
public void onCreate() {
super.onCreate();
FLTBackgroundGeolocationPlugin.setPluginRegistrant(this);
BackgroundFetchPlugin.setPluginRegistrant(this);
}

@OverRide
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}

@christocracy
Copy link
Member

Are you not actually watching $ adb logcat, as directed in the README?

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