brett lee
brett lee

Reputation: 1

GCM push notifications are not working in tablet

I am working on GCM Push notifications for my application. The GCM push notifications are working fine in Android 4.0.4 OS devices, but in HCL ME U1 tablet, they are not working. In that HCL tablet, playstore is also not working properly. Is it because of playstore that GCM push notifications are not working in the tablet?.

Can any one guide me how to fix this issue?

Upvotes: 0

Views: 1063

Answers (1)

con_9
con_9

Reputation: 2511

make sure u register this way and ur sender id is correct. Then you would recve a call to public final void onHandleIntent(Intent intent) overridden method of your class extending intentservice class. So what you should look at is, the error message that you get using intent.getStringExtra("error"); here intent object is you got in onHandleIntent method.This will tell you why google cudnt register your device.

try {
            GCMRegistrar.checkDevice(this);
            GCMRegistrar.checkManifest(this);
            //String regId = GCMRegistrar.getRegistrationId(this);
            SharedPreferences sharedPrefs = this.getSharedPreferences(
                    getApplicationContext().getPackageName(), Context.MODE_PRIVATE);
            //String regId = sharedPrefs.getString(myRegKey, "");
            //if(regId.equals(""))
            {
                Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
                registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
                registrationIntent.putExtra("sender", Your sender id here);
                startService(registrationIntent);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
    }

Edit1

@Override
        public final void onHandleIntent(Intent intent) {
            try {
                    String action = intent.getAction();
                    if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
                        handleRegistration(intent);
                    } else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
                        onMessage(this, intent);
                    }
               } catch (Exception ex) {
            ex.printStackTrace();
               } 
        }
protected void handleRegistration(Intent intent) {
        String registrationId = intent.getStringExtra("registration_id");
        String error = intent.getStringExtra("error");
        String unregistered = intent.getStringExtra("unregistered");  
//rest of code
}
protected void onMessage(Context context, Intent intent) {
        String title = intent.getStringExtra("title");
//rest of code
}

Can you tell me the values of registrationId, error, unregistered ?

Upvotes: 0

Related Questions