Issue Description
While sending push notifications from aws dashboard or my api, android doesnt detect any payload received. And if the application is in background the application crashes with the following stacktrace:
[ERROR] : APSCloudPush: Payload is null!
[ERROR] : TiApplication: (main) [727118,839001] 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 5.2.0,2015/11/25 11:26,1edba8d
[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:2776)
[ERROR] : TiApplication: at android.app.ActivityThread.-wrap14(ActivityThread.java)
[ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:148)
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5466)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Native Method)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
[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:2769)
[ERROR] : TiApplication: ... 8 more
Information
we tried the following structure for sending notifications:
Suggested By Appcelerator but not working
"data":{
"payload":{
"android": {
"alert": "This is a message from my own server"
}
}
}
AWS DEFAULT BUT NOT WORKING:
{
"default": "Welcome",
"GCM": "{ \"data\": { \"message\": \"Welcome\" } }"
}
WORKING ONE
But when we tried this, if app is in foreground it shows the message, but in background it crashes again :
{
"default": "Welcome",
"GCM": "{ \"data\": { \"payload\": \"Welcome\" } }"
}
Hi [~swapn1l] can you provide a runnable test case and state what device model/OS reproduces this on please?
Sample app.js
I've tested for this using my push notification app and I'm not running into any issues, I've tried with app closed, background and foreground, and after getting the push notification I run into no issues opening the app. Tested it on studio 5.1.2GA and 5.2.0v20160208101502, on android 5.1.1 and 6. Do you have any other information on it?
I am running into this crash when sending messages from another push provider (Parse). I am asked to keep parse while integrating other push notifications system, so when I send the message from Parse and it's received by CloudPush, it crashes! In this scenario, payload IS null by design. Crash is observed when app was in background, but it is sufficient to render the module unusable in any scenario where pushes come not only from ACS, but from other sources SDK : 5.1.2.GA Android : 5.1.1 Ti.Cloudpush version: 3.4.1
I'm also using an alternative push provider. To make it work you need to send the payload exactly how the CloudPush docs require. In my case: {"GCM": "{ \"data\": { \"payload\": { \"android\": { \"alert\": \"text notification\",\"icon\": \"appicon\" } }} }"} For me it's solved sending like this. Hope it helps.
As mentioned in previous comment cloudpush is meant to be used with arrow backend & not guranteed to work with other backends like aws.
Closing per dev comments. "cloudpush is meant to be used with arrow backend & not guranteed to work with other backends like aws"