diff options
Diffstat (limited to 'src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java')
-rw-r--r-- | src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java index 816d11118..f07167f8d 100644 --- a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java +++ b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java @@ -1,6 +1,7 @@ package de.pixart.messenger.services; import android.content.Intent; +import android.support.v4.content.ContextCompat; import android.util.Log; import com.google.firebase.messaging.FirebaseMessagingService; @@ -9,6 +10,7 @@ import com.google.firebase.messaging.RemoteMessage; import java.util.Map; import de.pixart.messenger.Config; +import de.pixart.messenger.utils.Compatibility; public class PushMessageReceiver extends FirebaseMessagingService { @@ -18,10 +20,19 @@ public class PushMessageReceiver extends FirebaseMessagingService { Log.d(Config.LOGTAG, "PushMessageReceiver ignored message because no accounts are enabled"); return; } - Map<String, String> data = message.getData(); - Intent intent = new Intent(this, XmppConnectionService.class); + final Map<String, String> data = message.getData(); + final Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED); intent.putExtra("account", data.get("account")); - startService(intent); + try { + if (Compatibility.runsAndTargetsTwentySix(this)) { + intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); + ContextCompat.startForegroundService(this, intent); + } else { + startService(intent); + } + } catch (IllegalStateException e) { + Log.e(Config.LOGTAG, "PushMessageReceiver is not allowed to start service"); + } } -} +}
\ No newline at end of file |