0

I have implemented GCM in android app. I cannot understand why I get push notification sometimes and sometimes I don't get.

GcmBroadcastReceiver

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        ComponentName comp = new ComponentName(context.getPackageName(),
                GCMNotificationIntentService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}

GCMNotificationIntentService

public class GCMNotificationIntentService extends IntentService {

    public GCMNotificationIntentService() {
        super("GCMNotificationIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();

        String Request_Type,Msg="",Time="",Date="",Firmid = "";

        String message = intent.getExtras().getString("price");
    }
}

Is there anything else I can do to ensure that the push notification is delivered everytime ?

Adrian
  • 1,677
  • 2
  • 12
  • 12
  • 2
    it's a environmental issue ,[read about it here](http://stackoverflow.com/questions/13835676/google-cloud-messaging-messages-sometimes-not-received-until-network-state-cha) – Pavneet_Singh Jul 21 '16 at 07:35
  • @PavneetSingh OK. What about FCM ? I hear that there are many changes in FCM and FCM is relatively reliable when compared to GCM. What is your view ? – Adrian Jul 21 '16 at 13:09
  • i think they almost follow the same terminology thought they are basically a service based company so yeah they have done improvements and to some limit most of them are free so i would recommend you to go through their price structure if ur planning to migrate DB to firebase – Pavneet_Singh Jul 21 '16 at 14:22
  • 1
    This [SO Question](http://stackoverflow.com/a/37453051/5995040) may inform you about **FCM Vs GCM? Why we need to migrate from GCM to FCM** – Mr.Rebot Jul 21 '16 at 15:25
  • @Adrian is correct FCM and GCM are very similar, note however that you are using the deprecated version of GCM so that may account for the fact that messages are sometimes not received. Even if you decide to use GCM please use the currently recommended version of it see sample here: https://github.com/googlesamples/google-services/tree/master/android/gcm – Arthur Thompson Jul 22 '16 at 18:43

0 Answers0