mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 12:51:16 +00:00
Fix app control by broadcast intents on Android 8 (fixes #976)
This commit is contained in:
parent
d925cbfdde
commit
07a9518437
2 changed files with 3 additions and 11 deletions
|
@ -12,9 +12,7 @@ import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast-receiver to control and configure SyncThing remotely
|
* Broadcast-receiver to control and configure Syncthing remotely.
|
||||||
*
|
|
||||||
* Created by sqrt-1764 on 25.03.16.
|
|
||||||
*/
|
*/
|
||||||
public class AppConfigReceiver extends BroadcastReceiver {
|
public class AppConfigReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@ -37,9 +35,8 @@ public class AppConfigReceiver extends BroadcastReceiver {
|
||||||
((SyncthingApp) context.getApplicationContext()).component().inject(this);
|
((SyncthingApp) context.getApplicationContext()).component().inject(this);
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case ACTION_START:
|
case ACTION_START:
|
||||||
context.startService(new Intent(context, SyncthingService.class));
|
BootReceiver.startServiceCompat(context);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_STOP:
|
case ACTION_STOP:
|
||||||
if (DeviceStateHolder.alwaysRunInBackground(context)) {
|
if (DeviceStateHolder.alwaysRunInBackground(context)) {
|
||||||
mNotificationHandler.showStopSyncthingWarningNotification();
|
mNotificationHandler.showStopSyncthingWarningNotification();
|
||||||
|
|
|
@ -27,12 +27,7 @@ public class BootReceiver extends BroadcastReceiver {
|
||||||
*
|
*
|
||||||
* https://stackoverflow.com/a/44505719/1837158
|
* https://stackoverflow.com/a/44505719/1837158
|
||||||
*/
|
*/
|
||||||
private static void startServiceCompat(Context context) {
|
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;
|
|
||||||
|
|
||||||
Intent intent = new Intent(context, SyncthingService.class);
|
Intent intent = new Intent(context, SyncthingService.class);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
context.startForegroundService(intent);
|
context.startForegroundService(intent);
|
||||||
|
|
Loading…
Reference in a new issue