GithubHelp home page GithubHelp logo

Comments (2)

lbdroid avatar lbdroid commented on June 21, 2024

Create basic foreground service like this (also adding the service to AndroidManifest.xml);

public class ForegroundService extends Service {
    private static final String LOG_TAG = "Tracker Service";
    private final String serviceChannelId = "tracker_detector_s";

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        // runs first
        super.onCreate();

        Log.d(LOG_TAG, "Running onCreate()");

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationChannel mChannel = new NotificationChannel(serviceChannelId, "Nextcloud Service", NotificationManager.IMPORTANCE_NONE);
            mChannel.setDescription("Tracker Detector Service");
            notificationManager.createNotificationChannel(mChannel);
        }

        Notification newNotification =
                new NotificationCompat.Builder(ForegroundService.this, serviceChannelId)
                        .setSmallIcon(android.R.drawable.ic_input_add)
                        .setContentTitle("Tracker-Service")
                        .setContentText("Keep gps working")
                        .build();

        startForeground(88811, newNotification);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // runs second
        return START_STICKY;
    }
}

Add this near the end of TrackingDetectorWorker.doWork():

        val service = Intent(getApplicationContext(), ForegroundService::class.java)
        getApplicationContext()!!.startForegroundService(service)

And rejigging ScanBluetoothWorker.doWork():

        Timber.d("Scanning for bluetooth le devices stopped!. Discovered ${scanResultDictionary.size} devices")

        if (SharedPrefs.useLocationInTrackingDetection && scanResultDictionary.size > 0) {
            val lastLocation = locationProvider.getLastLocation()

            if (lastLocation != null) {
                // Location matches the requirement. No need to request a new one
                location = lastLocation
                Timber.d("Using last location")
            } else {
                //Getting the most accurate location here
                locationProvider.getCurrentLocation { loc ->
                    this.location = loc
                    Timber.d("Updated to current location")
                }

                val fetchedLocation = this.waitForRequestedLocation()
                Timber.d("Fetched location? ${fetchedLocation}")
            }
        }

The above makes location acquisition work infinitely better.
The service doesn't have to do anything at all besides just sit there in the foreground in order to escape from the background location rate restrictions. The rejigging of ScanBluetoothWorker just avoids wasting power on finding a location if no bluetooth device was detected.

from airguard.

Sn0wfreezeDev avatar Sn0wfreezeDev commented on June 21, 2024

Hi,
Yes we fixed this issue in the next version. Stay tuned for the update 😊

from airguard.

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.