run LocationService on foreground
This commit is contained in:
parent
f26069db00
commit
d21080169d
3 changed files with 14 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation
|
package info.nightscout.androidaps.plugins.general.automation
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
@ -65,7 +66,10 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
val context = MainApp.instance().applicationContext
|
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()
|
super.onStart()
|
||||||
loadFromSP()
|
loadFromSP()
|
||||||
|
@ -76,9 +80,11 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe({ e ->
|
.subscribe({ e ->
|
||||||
if (e.isChanged(R.string.key_location)) {
|
if (e.isChanged(R.string.key_location)) {
|
||||||
val ctx = MainApp.instance().applicationContext
|
context.stopService(Intent(context, LocationService::class.java))
|
||||||
ctx.stopService(Intent(ctx, LocationService::class.java))
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
ctx.startService(Intent(ctx, LocationService::class.java))
|
context.startForegroundService(Intent(context, LocationService::class.java))
|
||||||
|
else
|
||||||
|
context.startService(Intent(context, LocationService::class.java))
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
FabricPrivacy.logException(it)
|
FabricPrivacy.logException(it)
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class PersistentNotificationPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Notification updateNotification() {
|
public Notification updateNotification() {
|
||||||
String line1 = null;
|
String line1 = null;
|
||||||
String line2 = null;
|
String line2 = null;
|
||||||
String line3 = null;
|
String line3 = null;
|
||||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventLocationChange;
|
import info.nightscout.androidaps.events.EventLocationChange;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
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.SP;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
|
|
||||||
|
@ -76,9 +77,10 @@ public class LocationService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
super.onStartCommand(intent, flags, startId);
|
||||||
if (L.isEnabled(L.LOCATION))
|
if (L.isEnabled(L.LOCATION))
|
||||||
log.debug("onStartCommand");
|
log.debug("onStartCommand");
|
||||||
super.onStartCommand(intent, flags, startId);
|
startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().updateNotification());
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue