Comments (23)
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.
Can you provide more details about your setup and the steps you took to lead to this question/issue?
from background_location.
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.
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.
i removed that line but still facing issue
from background_location.
it working when i put app on background but as i killed app not getting data
from background_location.
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.
from background_location.
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.
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.
@akabhinavv3 hello were you able to get location data on background but when the app is killed?
from background_location.
from background_location.
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.
any updates on reproducing this?
from background_location.
I have the same problem, does this package work to get the location even when the user has closed the app?
from background_location.
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.
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.
It is not a dart issue.
It's a normal behavior of the operating System.
from background_location.
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.
@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.
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.
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.
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.
This issue was closed because it has been stalled for 5 days with no activity.
from background_location.
Related Issues (20)
- Conflict between BackgroundLocation.getLocationUpdates and FirebaseMessaging.onBackgroundMessage HOT 3
- Flutter Android Version 3.0 Support HOT 5
- showing blue bar at the top of screen when app goes in background HOT 2
- is this plugin still working HOT 2
- background location not updating dynamically HOT 3
- Requesting Contributors HOT 9
- Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent HOT 2
- Lexical or Preprocessor Issue (Xcode): 'background_location/background_location-Swift.h' file not found HOT 5
- Not Working on reel devices iOS 17 but work correct-jy on android emulator HOT 3
- Allow disabling blue location usage bar when app is Always authorized to use location and running in background HOT 4
- Is there any property for direction? HOT 1
- Used for targetSdkVerison 34 HOT 1
- App crashed with targetSdkVersion 34, Error: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified HOT 23
- getLocationUpdates is not triggered after locking screen HOT 3
- Location not working in the background nor in forground HOT 2
- Accessing Location HOT 2
- Enabling Location access while screen is off HOT 2
- CI should not be trying to push to pub.dev for runs triggered by pull requests HOT 4
- Background location is poor quality on Android HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from background_location.