[AC-225] Android Error: Payload is null! when installing freshly on a device
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Cannot Reproduce |
Resolution Date | 2015-12-14T14:03:47.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Shawn Lan |
Assignee | Mostafizur Rahman |
Created | 2015-07-13T18:57:26.000+0000 |
Updated | 2016-03-01T18:38:27.000+0000 |
Description
My app uses android push notification. If I do a fresh install on my android phone, I get the following error. It behaves as if a push notification is coming in, but there is actually none.
[ERROR] : APSCloudPush: Payload is null!
[ERROR] : TiApplication: (main) [4889,4889] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start receiver com.appcelerator.aps.GCMReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference; Titanium 4.0.0,2015/05/18 15:42,9239ff9
[ERROR] : TiApplication: java.lang.RuntimeException: Unable to start receiver com.appcelerator.aps.GCMReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
[ERROR] : TiApplication: at android.app.ActivityThread.handleReceiver(ActivityThread.java:2726)
[ERROR] : TiApplication: at android.app.ActivityThread.access$1700(ActivityThread.java:144)
[ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:155)
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5696)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Native Method)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:372)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
[ERROR] : TiApplication:
[ERROR] : TiApplication: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
[ERROR] : TiApplication: at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
[ERROR] : TiApplication: at org.json.JSONTokener.nextValue(JSONTokener.java:94)
[ERROR] : TiApplication: at org.json.JSONObject.<init>(JSONObject.java:156)
[ERROR] : TiApplication: at org.json.JSONObject.<init>(JSONObject.java:173)
[ERROR] : TiApplication: at com.appcelerator.aps.APSCloudPush.showTrayNotification(APSCloudPush.java:347)
[ERROR] : TiApplication: at com.appcelerator.aps.APSCloudPush.receivePayload(APSCloudPush.java:253)
[ERROR] : TiApplication: at com.appcelerator.aps.GCMReceiver.onReceive(GCMReceiver.java:30)
[ERROR] : TiApplication: at android.app.ActivityThread.handleReceiver(ActivityThread.java:2712)
[ERROR] : TiApplication: ... 9 more
Here is the js code:
var CloudPush = require('ti.cloudpush');
var rc = CloudPush.isGooglePlayServicesAvailable();
if(rc == CloudPush.SUCCESS){
var flagBgPush = function(){
bgPush = true;
};
CloudPush.retrieveDeviceToken({
success: deviceTokenSuccess,
error: function(){}
});
CloudPush.addEventListener('trayClickLaunchedApp', flagBgPush);
CloudPush.addEventListener('trayClickFocusedApp', flagBgPush);
CloudPush.addEventListener('callback', pushBackgroundCheck);
}
I didn't specify a version number for ti.cloudpush in tiapp.xml, so it should be the latest version that's shipped with 4.0.0/4.1.0. This issue seems random. Not every time the issue shows up. But I'm sure the issue happens only at the first launch of a fresh install. If you just "update" the app, there is no such issue. I think you have to try uninstalling and reinstalling a few times to see it happen. Maybe send a few push notifications as well (I did).
I cannot say for sure, but I think the issue might have to do with the device trying to process a push notification before all of the notification stuff is setup. Try this and see if it reproduces the issue: 1.) Create an app and set it up to recieve push notifications. 2.) Install the app on an android device and run it, registering to receive push notifications from one or more channels. 3.) Verify in the appcelerator cloud services dashboard that the device is registered. 4.) Uninstall the app from the device. 5.) Using the cloud services dashboard, send a push notification to the device (which still shows up in the dashboard, even though it has been uninstalled). 6.) Reinstall and start the app on the device. See if the error appears.
and try uninstalling and reinstalling immediately. Not every time you'll see this error, but if you try enough times you should be able to get it.
Hi [~shawnlan] Can you please share with us your android device details? Thanks
HTC One M7, Sense 6.0. Android 5.0.2. Anything else you need?
I have the exact same issue. {noformat} E/APSCloudPush(14459): Payload is null! W/GCM-DMM ( 941): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=sh.dogfi.intrepid (has extras) } D/AndroidRuntime(14459): Shutting down VM W/dalvikvm(14459): threadid=1: thread exiting with uncaught exception (group=0x41614ba8) E/TiApplication(14459): (main) [46918,57276] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start receiver com.appcelerator.aps.GCMReceiver: java.lang.NullPointerException; Titanium 4.1.0,2015/07/06 11:15,d57aa7d E/TiApplication(14459): java.lang.RuntimeException: Unable to start receiver com.appcelerator.aps.GCMReceiver: java.lang.NullPointerException E/TiApplication(14459): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2426) E/TiApplication(14459): at android.app.ActivityThread.access$1700(ActivityThread.java:135) E/TiApplication(14459): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272) E/TiApplication(14459): at android.os.Handler.dispatchMessage(Handler.java:102) E/TiApplication(14459): at android.os.Looper.loop(Looper.java:136) E/TiApplication(14459): at android.app.ActivityThread.main(ActivityThread.java:5017) E/TiApplication(14459): at java.lang.reflect.Method.invokeNative(Native Method) E/TiApplication(14459): at java.lang.reflect.Method.invoke(Method.java:515) E/TiApplication(14459): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) E/TiApplication(14459): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) E/TiApplication(14459): at dalvik.system.NativeStart.main(Native Method) E/TiApplication(14459): Caused by: java.lang.NullPointerException E/TiApplication(14459): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) E/TiApplication(14459): at org.json.JSONTokener.nextValue(JSONTokener.java:94) E/TiApplication(14459): at org.json.JSONObject.
[~jyounus] hey, can you reproduce this with the same test case in the ticket? is this also reproducible with some other devices?
Hey Radamantis, We managed to solve the issue. Okay, so the above test case (and our own app project) works fine if we use the ACS dashboard for sending test push notifications. No problems there, no crash and the app receives the notification just fine. However, we are using PubNub and their push notification service, which does NOT work with Ti.Cloud and the Ti.CloudPush module. We didn't know that, don't think that's very obvious at all for people that are new to push notifications (like me D: ). We kept sending push notifications via PubNub but the app just wouldn't receive them. Ti.Cloud and Ti.CloudPush modules seem to be specifically for ACS. We ended up using this module here: https://github.com/CaffeinaLab/GCM Anyone else that's having the same issue and isn't using ACS for push notifications, use the above module. That should hopefully do the trick for you.
Well, I'm using ACS and still have such issue. It happens sometimes when uninstalling and reinstalling the app (no push notification is sent at the time).
Hey, in order to re-produce, you have to subscribe to channel in the beginning. (Cloud.PushNotifications.subscribeToken) If in your app you don't subscribe to channel at all, you won't see the error. You might still need to uninstall and reinstall several times to re-produce.
We have re-tested this issue with our updated environment SDK 5.1.1.GA With Cloudpush v3.4.0. We can not reproduce this issue. Thanks.
I have it now. My environment is 5.1.2.GA and my cloudpush is 3.4.1 I have both Ti.Parse and Cloudpush. When I send push notifications from Parse, app crashes with this message, because in case of Parse messages, payload IS null. var CloudPush = require('ti.cloudpush'); CloudPush.debug = true; CloudPush.enabled = true; CloudPush.showTrayNotificationsWhenFocused = true; CloudPush.focusAppOnPush = false; CloudPush.retrieveDeviceToken({ success: function deviceTokenSuccess(e) { Ti.API.info('Cloudpush Device Token: ' + e.deviceToken); }, error: function deviceTokenError(e) { alert('Failed to register for push! ' + e.error); } }); // These events monitor incoming push notifications CloudPush.addEventListener('callback', pushNotificationCallback); CloudPush.addEventListener('trayClickLaunchedApp', function (evt) { Ti.API.info('Tray Click Launched App (app was not running)'); }); CloudPush.addEventListener('trayClickFocusedApp', function (evt) { Ti.API.info('Tray Click Focused App (app was already running)'); });
Do you always have this problem? Or only sometimes after a fresh install?
You are right, I noticed it after fresh install. But I cannot test anymore, because I already switched to another gcm module (nl.vanvianen.android.gcm) The problem I was having yesterday is that the app would not wake up from background on messages with or without payload, so probably it was not crashing. Still, it was not waking up, this is why I did a fresh install today. I was receiving Push with Ti.Parse and CloudPush, and Ti.Parse without cloudpush does wake it up just fine. My process was like this: 1. Install Ti.Parse (with a modification to get token). App wakes up. 2. I realised that Ti.Parse does not process all messages, so I need another module 3. Installed CloudPush. 4. Messages were being processed in foreground, but not when the app is backgrounded. Went to bed. 5. Morning I did a clean install and tried again. Cloudpush crashed. 6. Uninstall Cloudpush, leaving only Parse - back to step 1, everything works fine. 7. .... here I accidentally updated Appcelerator and had to reinstall node.js and Studio, because of another bug, so after I was done with fixing environment, in TiSlack they told me that this conversation already took place 2 weeks ago and most people use nl.vanvianen.android.gcm instead of CloudPush 8. Now I have that other module and everything works fine, so I donĀ“t want to spoil it.
Thanks for the info. By the way, Parse is shutting down.