Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20291] Android: Push Notification Payload Null

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Do
Resolution Date2019-11-15T22:30:15.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
LabelsANDROID, AWS, Appcelerator, Notifications, Push, SNS
ReporterSwapnil Singh
AssigneeAshraf Abu
Created2016-01-06T12:15:44.000+0000
Updated2019-11-15T22:30:15.000+0000

Description

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\" } }"
}

Comments

  1. Eduardo Gomez 2016-01-29

    Hi [~swapn1l] can you provide a runnable test case and state what device model/OS reproduces this on please?
  2. Eduardo Gomez 2016-02-08

    Sample app.js

       var win = Ti.UI.createWindow({
           layout: 'vertical',
           backgroundColor: 'white'
       });
       
       var CloudPush = require('ti.cloudpush');
       
       var code = CloudPush.isGooglePlayServicesAvailable();
       if (code != CloudPush.SUCCESS) {
           alert ("Google Play Services is not installed/updated/available");
       }
       
       CloudPush.addEventListener('callback', function (evt) {
           alert(evt.payload);
       });
       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)');
       });
       
       /*
        * Create a label to show Push type
        */
       var pushTypeLabel = Ti.UI.createLabel({
           top: '10dp', width: '320dp', height: '25dp',
           textAlign: 'center', font: { fontSize:14}, color: 'black',
           text: 'Push Type: ' + CloudPush.pushType
       });
       win.add(pushTypeLabel);
       
       /*
        * Create a label to show device token on screen
        */
       var deviceTokenLabel = Ti.UI.createLabel({
           top: '10dp', width: '320dp', height: (CloudPush.pushType=='gcm'?'150dp':'40dp'),
           font: { fontSize:14}, color: 'black',
           text: 'Device Token'
       });
       win.add(deviceTokenLabel);
       
       CloudPush.retrieveDeviceToken({
           success: deviceTokenSuccess,
           error: deviceTokenError
       });
       
       function deviceTokenSuccess(e) {
           Ti.API.info('Device Token: ' + e.deviceToken);
           deviceTokenLabel.text = 'Device Token:' + e.deviceToken;
           enablePush.enabled = true;
       }
       
       function deviceTokenError(e) {
           alert('Failed to register for push! ' + e.error);
           deviceTokenLabel.text = 'Failed to get device token.';
       }
       
       /*
        Push can be enabled or disabled.
        */
       var enablePush = Ti.UI.createButton({
           top: '10dp', width: '320dp', height: '40dp',
           enabled: false
       });
       enablePush.addEventListener('click', function () {
           enablePush.title = CloudPush.enabled ? 'Disabling...' : 'Enabling...';
           CloudPush.enabled = !CloudPush.enabled;
           // NOTE: Push.enabled takes a moment to update after you change its value.
           setTimeout(syncButtons, 500);
       });
       win.add(enablePush);
       
       /*
        Whether or not to show a tray notification.
        */
       var showTrayNotification = Ti.UI.createButton({
           top: '10dp', width: '320dp', height: '40dp'
       });
       showTrayNotification.addEventListener('click', function () {
           CloudPush.showTrayNotification = !CloudPush.showTrayNotification;
           syncButtons();
       });
       win.add(showTrayNotification);
       
       /*
        Whether or not clicking a tray notification focuses the app.
        */
       var showAppOnTrayClick = Ti.UI.createButton({
           top: '10dp', width: '320dp', height: '40dp'
       });
       showAppOnTrayClick.addEventListener('click', function () {
           CloudPush.showAppOnTrayClick = !CloudPush.showAppOnTrayClick;
           syncButtons();
       });
       win.add(showAppOnTrayClick);
       
       /*
        Whether or not tray notifications are shown when the app is in the foreground.
        */
       var showTrayNotificationsWhenFocused = Ti.UI.createButton({
           top: '10dp', width: '320dp', height: '40dp'
       });
       showTrayNotificationsWhenFocused.addEventListener('click', function () {
           CloudPush.showTrayNotificationsWhenFocused = !CloudPush.showTrayNotificationsWhenFocused;
           syncButtons();
       });
       win.add(showTrayNotificationsWhenFocused);
       
       /*
        Whether or not receiving a push immediately brings the application to the foreground.
        */
       var focusAppOnPush = Ti.UI.createButton({
           top: '10dp', width: '320dp', height: '40dp'
       });
       focusAppOnPush.addEventListener('click', function () {
           CloudPush.focusAppOnPush = !CloudPush.focusAppOnPush;
           syncButtons();
       });
       win.add(focusAppOnPush);
       
       /*
        Trigger callbacks together or one by one when multiple push notifications come.
        */
       var singleCallback = Ti.UI.createButton({
           top: '10dp', width: '320dp', height: '40dp'
       });
       singleCallback.addEventListener('click', function () {
           CloudPush.singleCallback = !CloudPush.singleCallback;
           syncButtons();
       });
       win.add(singleCallback);
       
       function syncButtons() {
           enablePush.title = CloudPush.enabled ? 'Push Enabled' : 'Push Disabled';
           showAppOnTrayClick.title = CloudPush.showAppOnTrayClick ? 'Tray Click Shows App' : 'Tray Click Does Nothing';
           showTrayNotification.title = CloudPush.showTrayNotification ? 'Show in Tray' : 'Do Not Show in Tray';
           focusAppOnPush.title = CloudPush.focusAppOnPush ? 'Push Focuses App' : 'Push Doesn\'t Focus App';
           showTrayNotificationsWhenFocused.title = CloudPush.showTrayNotificationsWhenFocused ? 'Show Trays when Focused' : 'Hide Trays when Focused';
           singleCallback.title = CloudPush.singleCallback ? 'Callbacks trigger one by one' : 'Callbacks trigger together';
       }
       
       syncButtons();
       win.open();
       
  3. Nathan Cook 2016-02-09

    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?
  4. Ganna Kozynenko 2016-03-01

    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
  5. Arildo Junior 2016-07-25

    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.
  6. Lokesh Choudhary 2019-10-09

    As mentioned in previous comment cloudpush is meant to be used with arrow backend & not guranteed to work with other backends like aws.
  7. Alan Hutton 2019-11-15

    Closing per dev comments. "cloudpush is meant to be used with arrow backend & not guranteed to work with other backends like aws"

JSON Source