diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-11-23 14:22:01 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-11-23 14:22:01 +0100 |
commit | 5af8fae06ff1e9a26e544a22c1ea40b4a5144353 (patch) | |
tree | d41117a87c2d69d6595a2c51b8795ca1e3bc0f7d /src/main/java | |
parent | fcea59be2be60164f82d23e45d5fe1d858fa9322 (diff) |
use startForegroundService compat from push message receiver
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/EventReceiver.java | 4 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/services/EventReceiver.java b/src/main/java/de/pixart/messenger/services/EventReceiver.java index a77db569e..03bf68ed9 100644 --- a/src/main/java/de/pixart/messenger/services/EventReceiver.java +++ b/src/main/java/de/pixart/messenger/services/EventReceiver.java @@ -13,6 +13,7 @@ import de.pixart.messenger.utils.Compatibility; public class EventReceiver extends BroadcastReceiver { public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts"; + public static final String EXTRA_NEEDS_FOREGROUND_SERVICE = "needs_foreground_service"; @Override public void onReceive(final Context context, final Intent originalIntent) { @@ -26,6 +27,7 @@ public class EventReceiver extends BroadcastReceiver { if (action.equals("ui") || hasEnabledAccounts(context)) { try { if (Compatibility.runsAndTargetsTwentySix(context)) { + intentForService.putExtra(EXTRA_NEEDS_FOREGROUND_SERVICE, true); ContextCompat.startForegroundService(context, intentForService); } else { context.startService(intentForService); @@ -42,4 +44,4 @@ public class EventReceiver extends BroadcastReceiver { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS, true); } -} +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index c0c3c7dec..9d0071af2 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -581,6 +581,11 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { final String action = intent == null ? null : intent.getAction(); + final boolean needsForegroundService = intent != null && intent.getBooleanExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, false); + if (needsForegroundService) { + Log.d(Config.LOGTAG, "toggle forced foreground service after receiving event"); + toggleForegroundService(true); + } String pushedAccountHash = null; boolean interactive = false; if (action != null) { @@ -1243,8 +1248,12 @@ public class XmppConnectionService extends Service { } public void toggleForegroundService() { + toggleForegroundService(false); + } + + private void toggleForegroundService(boolean force) { final boolean status; - if (mForceForegroundService.get() || (Compatibility.keepForegroundService(this)/* && hasEnabledAccounts()*/)) { + if (force || mForceForegroundService.get() || (Compatibility.keepForegroundService(this)/* && hasEnabledAccounts()*/)) { startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification()); status = true; } else { |