diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-09-12 22:32:47 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-09-13 17:29:36 +0200 |
commit | 46b77bf34219aa47e916f0ab980d3bd5bb05ba34 (patch) | |
tree | 0a73271b9cdea5577b7d69dbdbf525f24bcc31b7 /src/main/java/de/pixart/messenger/services/EventReceiver.java | |
parent | e50ba72e8ae024e64b1e2b2838f73faf64330adb (diff) |
initial work toward api 26+
* introduce notification channels
* always use foreground service on 26+
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/EventReceiver.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/EventReceiver.java | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main/java/de/pixart/messenger/services/EventReceiver.java b/src/main/java/de/pixart/messenger/services/EventReceiver.java index 6200a40ce..529741ead 100644 --- a/src/main/java/de/pixart/messenger/services/EventReceiver.java +++ b/src/main/java/de/pixart/messenger/services/EventReceiver.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.preference.PreferenceManager; +import android.support.v4.content.ContextCompat; import android.util.Log; import de.pixart.messenger.Config; @@ -13,26 +14,26 @@ public class EventReceiver extends BroadcastReceiver { public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts"; @Override - public void onReceive(Context context, Intent intent) { - Intent mIntentForService = new Intent(context, XmppConnectionService.class); - if (intent.getAction() != null) { - mIntentForService.setAction(intent.getAction()); + public void onReceive(final Context context, final Intent originalIntent) { + final Intent intentForService = new Intent(context, XmppConnectionService.class); + if (originalIntent.getAction() != null) { + intentForService.setAction(originalIntent.getAction()); } else { - mIntentForService.setAction("other"); + intentForService.setAction("other"); } - final String action = intent.getAction(); + final String action = originalIntent.getAction(); if (action.equals("ui") || hasEnabledAccounts(context)) { try { - context.startService(mIntentForService); + ContextCompat.startForegroundService(context, intentForService); } catch (RuntimeException e) { Log.d(Config.LOGTAG, "EventReceiver was unable to start service"); } } else { - Log.d(Config.LOGTAG, "EventReceiver ignored action " + mIntentForService.getAction()); + Log.d(Config.LOGTAG, "EventReceiver ignored action " + intentForService.getAction()); } } - public static boolean hasEnabledAccounts(Context context) { + public static boolean hasEnabledAccounts(final Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS, true); } |