1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-23 04:41:16 +00:00

Fix app control by broadcast intents on Android 8 (fixes #976)

This commit is contained in:
Felix Ableitner 2017-10-23 22:59:21 +09:00
parent d925cbfdde
commit 07a9518437
2 changed files with 3 additions and 11 deletions

View file

@ -12,9 +12,7 @@ import com.nutomic.syncthingandroid.service.SyncthingService;
import javax.inject.Inject;
/**
* Broadcast-receiver to control and configure SyncThing remotely
*
* Created by sqrt-1764 on 25.03.16.
* Broadcast-receiver to control and configure Syncthing remotely.
*/
public class AppConfigReceiver extends BroadcastReceiver {
@ -37,9 +35,8 @@ public class AppConfigReceiver extends BroadcastReceiver {
((SyncthingApp) context.getApplicationContext()).component().inject(this);
switch (intent.getAction()) {
case ACTION_START:
context.startService(new Intent(context, SyncthingService.class));
BootReceiver.startServiceCompat(context);
break;
case ACTION_STOP:
if (DeviceStateHolder.alwaysRunInBackground(context)) {
mNotificationHandler.showStopSyncthingWarningNotification();

View file

@ -27,12 +27,7 @@ public class BootReceiver extends BroadcastReceiver {
*
* https://stackoverflow.com/a/44505719/1837158
*/
private static void startServiceCompat(Context context) {
// This method is called from {@link DeviceStateHolder#DeviceStateHolder()}, make sure it
// is only executed if run in background is enabled.
if (!DeviceStateHolder.alwaysRunInBackground(context))
return;
static void startServiceCompat(Context context) {
Intent intent = new Intent(context, SyncthingService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);