Comments (2)
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.
Hi,
Yes we fixed this issue in the next version. Stay tuned for the update 😊
from airguard.
Related Issues (20)
- rename device HOT 3
- Add support for Kisha Umbrella beacons HOT 1
- Enable coasting for pinch-zooming in map view HOT 1
- App crashes on application startup after setup HOT 1
- Migrate gradle script to Kotlin DSL HOT 3
- Publish 2.1.0 on PlayStore and F-Droid HOT 1
- Feature Request: Allow naming of known devices. HOT 2
- Optionally include logging of generic Bluetooth devices in addition to known tracker types HOT 1
- Thank you!
- Scanning animation could be problematic for some users
- Playing sound on Tile trackers HOT 1
- Protecting screen from prying apps (screenshots, recent apps)
- Including in scanning also unknown devices (not Apple and DIY ones) HOT 2
- Make the donation process easier (to support development) HOT 1
- Adding autoscan toggle (off/on) in settings
- Set gps "safe" areas, and then set ON bluetooth only when I am outside of them
- Assign recognizable names to MAC addresses
- [Bug; low priority] UI colors on scanner tabs aren't properly contrasted
- [Bug] Duplicate readouts
- [Bug] Constant crashes since update
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 airguard.