interman
interman

Reputation: 141

Android GCM push has delivery to device but not route to my app sometimes

I have a problem that GCM message push to my device, but not route to my app sometimes, especially when my app just start up. I read the following line to logcat:

I/GCM     ( 5227): GCM message com.info.chat 0:1423053966153011%64523c3ff9fd7dcc
D/ConnectivityService(  774): handleInetConditionHoldEnd: net=0, condition=100, published condition=100
I/Ads     (20754): Ad is not visible. Not refreshing ad.
I/Ads     (20754): Scheduling ad refresh 60000 milliseconds from now.
W/GCM-DMM ( 5227): Force release of GOOGLE_C2DM lock

Then I don't see any log for my app to processing the message.

However, sometimes, it will success, and the log look like:

I/GCM     ( 5227): GCM message com.info.chat 0:1423054244269861%64523c3ff9fd7dcc
D/com.info.chat( 8263): <8263>[GCMBroadcastReceiver.onReceive 24]Received a GCM   Broadcast : Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=com.info.chat cmp=com.info.chat/.GCMBroadcastReceiver (has extras) }

In my program, I create GCMBroadcastReceiver to listen the GCM broadcast

public class GCMBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    Log.d("Received a GCM Broadcast : "+intent);

    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
                                           GCMIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));

    setResultCode(Activity.RESULT_OK);
}

and the manifest :

    <permission android:name="com.info.chat.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    <uses-permission android:name="com.info.chat.permission.C2D_MESSAGE" />
    <receiver
        android:name="com.info.chat.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.info.chat" />
        </intent-filter>
    </receiver>       

So any one can help to make sure the message should route to my app?

Upvotes: 2

Views: 1007

Answers (1)

Uncaught Exception
Uncaught Exception

Reputation: 2179

Google guarantees delivery of GCM/FCM messages to the device. Once it reaches the device, Google Play Services broadcasts it to the registered client (it starts the process of the client if not already started). So, if your app/service is not receiving the GCM message, that indicates that the process of your app has gone 'bad'. This happens when your app crashes so frequently that the OS force stops it; in this 'bad' state, your app can't receive any GCM messages.

Logcat will show a log like below, indicating the cancelled broadcast:

12-06 18:37:31.802 3566-3566/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=your_pkg_name (has extras) }

Also note that, when your app crashes, the crash dialog stays for 5 mins; in those 5 mins, neither your app will receive any FCM messages, nor any other external broadcasts(e.g. registered broadcast in manifest for ACTION_POWER_CONNECTED etc). Once those 5 mins are elapsed and dialog disappeared, then your app will function normally.

A classic case would be of an app in which there is an exception in onCreate() itself.This one would become a prime candidate for bad process. App will not get auto-updated through playstore when in bad state; however it could be updated manually by going to playstore or by rebooting the phone. Note: Atleast my experience with Nexus 5x has been that we need not remove the battery to get the app out of the bad state; reboot is enough.

Upvotes: 1

Related Questions