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

Not working in WorkManager #27

Open
waqarv712 opened this issue Apr 14, 2020 · 3 comments
Open

Not working in WorkManager #27

waqarv712 opened this issue Apr 14, 2020 · 3 comments

Comments

@waqarv712
Copy link

I am using this code:

private void getLocationUpdates() {

            TrackerSettings settings =
                    new TrackerSettings()
                            .setUseGPS(true)
                            .setUseNetwork(true)
                            .setUsePassive(true);
//                            .setTimeBetweenUpdates(5000);
//                            .setTimeBetweenUpdates(30 * 60 * 1000)
//                            .setMetersBetweenUpdates(100);

            LocationTracker tracker = new LocationTracker(getApplicationContext(), settings) {
                @Override
                public void onLocationFound(Location location) {
                    // Do some stuff

                    String latlng = location.getLatitude() + ", " + location.getLongitude();

                    Log.d("WorkManager", "onLocationFound: " + latlng);

                }

                @Override
                public void onTimeout() {
                    Log.d("WorkManager", "onTimeout: ");
                }
            };
            tracker.startListening();
    }

in the doWrok() function of WorkManager.
But this code works in the Service.

@quentin7b
Copy link
Owner

The tracked is based on the android.location.LocationManager class. So there is no reference on any service of any kind in the library.
I'm not familiar with the WorkManager yet, but if there a chance of the tracked being destroyed after the dowork call ?

@pioneersingh321
Copy link

in doWork() function you can make BroadcastReceiver.

Intent intent = new Intent(context, LocationBroadcastReceiver.class);
context.sendBroadcast(intent);

and call the library functions in BroadcastReceiver

hope it will work .. i have not tried but i have seen in some examples

@ballerburg9005
Copy link

ballerburg9005 commented May 1, 2023

WorkManager is used for battery-friendly background tasks, and it is the normal and only clean way to run background processes.

If you want to "track" your location, it mainly makes sense to do so in the background. So support for this should be very high priority.

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

4 participants