ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

ClassCastException Crash when app is open #271

Closed divydeep closed 7 years ago

divydeep commented 7 years ago

When I send a push to my app and the app is in the foreground I am getting the following error - `` 10-13 02:57:29.042 9135-10044/com.mypackage W/Bundle: Key google.sent_time expected String but value was a java.lang.Long. The default value was returned.

10-13 02:20:40.097 26760-10078/com.mypackage W/Bundle: Attempt to cast generated internal exception: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String at android.os.BaseBundle.getString(BaseBundle.java:995) at com.google.android.gms.gcm.zza.zzae(Unknown Source) at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source) at com.google.android.gms.gcm.GcmListenerService.zzn(Unknown Source) at com.google.android.gms.gcm.GcmListenerService.zzm(Unknown Source) at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source) at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) 10-13 02:20:40.098 26760-10078/com.mypackage I/System.out: GCMIntentService.onMessageReceived``

But when the app is in background, I don't receive this error and everything works fine.

divydeep commented 7 years ago

Was reading on stack overflow and it seems that Google made some changes around end-July or early August.

eladnava commented 7 years ago

@divydeep Any chance you are sending a notification with just the notification field and no payload?

https://github.com/rpush/rpush/issues/292

divydeep commented 7 years ago

@eladnava No, I am sending data payload with the notification

eladnava commented 7 years ago

@divydeep Are you by any chance reading from the intent extras in your GCM BroadcastReceiver and casting to String / Long?

divydeep commented 7 years ago

Yes, the bundle in the intent had one variable with wrong casting that was causing the issue. My bad. Fixed it by resolving the casting error.