GCM push notifications on Android 3.1: disable broadcast receiver

There was a problem with Android push notifications (GCM) on Android 3.1: when my application is closed, the broadcast receiver that should handle GCM (Intents) push messages is never called.

In lower versions of Android, everything works fine. The broadcast receiver is always called (even when the application is closed).

I know that with Android 3.1 a new concept has appeared: when the application does not work, it is in the β€œstopped” state: http://developer.android.com/about/versions/android-3.1.html#launchcontrols

So, if you want to start a "stopped" application through Intent, you must add the FLAG_INCLUDE_STOPPED_PACKAGES flag to Intent.

But the problem is that I cannot add the FLAG_INCLUDE_STOPPED_PACKAGES flag to the GCM intent because GCM Intents (I mean "com.google.android.c2dm.intent.RECEIVE" and "com.google.android.c2dm.intent. REGISTRATION ") are discarded by the OS.

So my question is: how can I process push messages (on android 3.1) from GCM through a broadcast receiver in a situation where the application (in which the broadcast is registered) is closed (in the "stopped" state)?

+6
source share
1 answer

how can I process push messages (on android 3.1) from GCM via a broadcast receiver in a situation where the application (in which the broadcast is registered) is closed (in the "stopped" state)?

You can not. If the user forcibly stops your application, nothing from your application will start again (on Android 3.1+) unless it is called manually, for example, when the user launches one of your actions. Your goal is to provide the user with no reason to force stop your application.

+7
source

Source: https://habr.com/ru/post/924751/


All Articles