run LocationService on foreground

This commit is contained in:
Milos Kozak 2019-08-08 19:53:25 +02:00
parent f26069db00
commit d21080169d
3 changed files with 14 additions and 6 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.general.automation
import android.content.Intent
import android.os.Build
import android.os.Handler
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
@ -65,7 +66,10 @@ object AutomationPlugin : PluginBase(PluginDescription()
override fun onStart() {
val context = MainApp.instance().applicationContext
context.startService(Intent(context, LocationService::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
context.startForegroundService(Intent(context, LocationService::class.java))
else
context.startService(Intent(context, LocationService::class.java))
super.onStart()
loadFromSP()
@ -76,9 +80,11 @@ object AutomationPlugin : PluginBase(PluginDescription()
.observeOn(Schedulers.io())
.subscribe({ e ->
if (e.isChanged(R.string.key_location)) {
val ctx = MainApp.instance().applicationContext
ctx.stopService(Intent(ctx, LocationService::class.java))
ctx.startService(Intent(ctx, LocationService::class.java))
context.stopService(Intent(context, LocationService::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
context.startForegroundService(Intent(context, LocationService::class.java))
else
context.startService(Intent(context, LocationService::class.java))
}
}, {
FabricPrivacy.logException(it)

View file

@ -123,7 +123,7 @@ public class PersistentNotificationPlugin extends PluginBase {
}
@Nonnull
Notification updateNotification() {
public Notification updateNotification() {
String line1 = null;
String line2 = null;
String line3 = null;

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventLocationChange;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.T;
@ -76,9 +77,10 @@ public class LocationService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
if (L.isEnabled(L.LOCATION))
log.debug("onStartCommand");
super.onStartCommand(intent, flags, startId);
startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().updateNotification());
return START_STICKY;
}