Giter Site home page Giter Site logo

Comments (23)

DavidIjsud avatar DavidIjsud commented on August 17, 2024 1

i guess it would not work at least the dart code that is running on flutter engine would not work if user kills/terminates/swipe up the app on ios because once the app is killed the flutter engine is killed as well, at least there is a way to keep the engine running even if the app is killed/terminated.
If i am wrong correct me.

So my solution for me was to create swift code and i realized that is better.

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

Can you provide more details about your setup and the steps you took to lead to this question/issue?

from background_location.

akabhinavv3 avatar akabhinavv3 commented on August 17, 2024

import 'package:flutter/material.dart';
import 'package:background_location/background_location.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
@OverRide
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
@OverRide
void initState() {
super.initState();
initBackgroundLocation();
}

void initBackgroundLocation() async {
await BackgroundLocation.setAndroidNotification(
title: 'Background service is running',
message: 'Background location in progress',
icon: '@mipmap/ic_launcher',
);

await BackgroundLocation.startLocationService(distanceFilter: 20);


BackgroundLocation.setAndroidConfiguration(3); // Set the update interval to 300 seconds (5 minutes)

BackgroundLocation.getLocationUpdates((location) {
  // Handle location updates here
  print('Location update: ${location.latitude}, ${location.longitude}');
});

// Start the location service explicitly when the app starts
BackgroundLocation.startLocationService();

}

@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Background Location Service'),
),
body: Center(
child: Text('App is running in the background fetching location...'),
),
),
);
}

@OverRide
void dispose() {
BackgroundLocation.stopLocationService();
super.dispose();
}
}

this is what i implemented

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

one thing i notice immediately upon skimming that code is that it seems like you're calling BackgroundLocation.startLocationService(); twice (once with a distance filter of 20 and once again a few lines later.

Could this be causing issues? is there a particular reason you chose to do it this way?

from background_location.

akabhinavv3 avatar akabhinavv3 commented on August 17, 2024

i removed that line but still facing issue

from background_location.

akabhinavv3 avatar akabhinavv3 commented on August 17, 2024

it working when i put app on background but as i killed app not getting data

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

so you want the app to keep getting location data after you go to the app switcher and swipe up to kill the app?

from background_location.

akabhinavv3 avatar akabhinavv3 commented on August 17, 2024

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

What android version are you using? it seems like you may need to add an additional permission to your manifest: https://stackoverflow.com/questions/69344149/cant-access-location-after-app-is-killed

from background_location.

github-actions avatar github-actions commented on August 17, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

from background_location.

DavidIjsud avatar DavidIjsud commented on August 17, 2024

@akabhinavv3 hello were you able to get location data on background but when the app is killed?

from background_location.

akabhinavv3 avatar akabhinavv3 commented on August 17, 2024

from background_location.

github-actions avatar github-actions commented on August 17, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

any updates on reproducing this?

from background_location.

EdHuamani avatar EdHuamani commented on August 17, 2024

I have the same problem, does this package work to get the location even when the user has closed the app?

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

even when the user has closed the app?

as in if the user swipes up from the system tray to close the app?

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

Im not personally too familiar with the internals of a dart plugin. I suspect it should be possible since the plugin has to hook into swift apis anyway.

I'm just not sure whether iOS or Android allow apps to run after the user explicitly kills them as that could be misused for all sorts of nefarious things.

from background_location.

xunreal75 avatar xunreal75 commented on August 17, 2024

It is not a dart issue.
It's a normal behavior of the operating System.

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

did a little research, seems like this is indeed not allowed by iOS. Android may have a little more flexibility it seems

iOS: https://stackoverflow.com/a/40449758
Android: https://stackoverflow.com/questions/23007924/how-to-run-a-thread-in-the-background-after-the-app-is-killed

Based on OP's submitted code sample, it seems as though they are on Android. I don't 100% know for sure whether killing the app also kills any associated background services/active foreground notifications, but I suspect either its not possible, or something may be misconfigured in the library.

More investigation and details are needed.

@akabhinavv3 Could you please provide the version numbers you are using for: android, flutter, and this library? It would also help if you could search through closed issues on this repo and confirm whether any of them might apply to your usecase

from background_location.

DavidIjsud avatar DavidIjsud commented on August 17, 2024

@MoralCode ios allows get updated locations when the app is killed, but it does not depend on when you want , it depends on when the system considers to launch your app in background, so when the SO launchs your app on background then in that moment you have to do what you want.

https://developer.apple.com/documentation/corelocation/cllocationmanager/1423531-startmonitoringsignificantlocati

on android it is allowed as well to get updated locations when the app is killed, and it is done with local notifications to alert user that something is occuring in background of the app, workmanager to schedule a service to run every certain time you want and this service will be in charger of get the currrent user locations and send that data where ever you want.

https://developer.android.com/develop/sensors-and-location/location/background.

i will try to do a small example integrated with flutter.

from background_location.

MoralCode avatar MoralCode commented on August 17, 2024

i will try to do a small example integrated with flutter.

That would be awesome!

This also seems to previously have been a feature in #92. @Almoullim may know more about how this is supposed to work or may be more able to fix the existing functionality

from background_location.

github-actions avatar github-actions commented on August 17, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

from background_location.

github-actions avatar github-actions commented on August 17, 2024

This issue was closed because it has been stalled for 5 days with no activity.

from background_location.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.