Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

payload is null, parse json

$
0
0

Titanium SDK:3.4.0 platform Android 4.4.4 on physical device i'm working on mac OSX

Payload is null

my json:

registration_ids:["APA91b...."],"data":{"message:"foo"}}

Log [ERROR] : APSCloudPush: Payload is null! [ERROR] : TiApplication: (main) [1194916,1541260] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start receiver com.appcelerator.cloudpush.GCMReceiver: java.lang.NullPointerException; Titanium 3.4.0,2014/09/25 16:42,b54c467 [ERROR] : TiApplication: java.lang.RuntimeException: Unable to start receiver com.appcelerator.cloudpush.GCMReceiver: java.lang.NullPointerException [ERROR] : TiApplication: at android.app.ActivityThread.handleReceiver(ActivityThread.java:2476) [ERROR] : TiApplication: at android.app.ActivityThread.access$1700(ActivityThread.java:144) [ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322) [ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102) [ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:212) [ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5135) [ERROR] : TiApplication: at java.lang.reflect.Method.invokeNative(Native Method) [ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:515) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) [ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method) [ERROR] : TiApplication: Caused by: java.lang.NullPointerException [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:155) [ERROR] : TiApplication: at org.json.JSONObject.<init>(JSONObject.java:172) [ERROR] : TiApplication: at com.appcelerator.cloudpush.APSCloudPush.showTrayNotification(APSCloudPush.java:334) [ERROR] : TiApplication: at com.appcelerator.cloudpush.APSCloudPush.receivePayload(APSCloudPush.java:240) [ERROR] : TiApplication: at com.appcelerator.cloudpush.GCMReceiver.onReceive(GCMReceiver.java:31) [ERROR] : TiApplication: at android.app.ActivityThread.handleReceiver(ActivityThread.java:2469) [ERROR] : TiApplication: ... 10 more

CODE

if (Ti.Platform.osname=="android"){

    //to use push notification of google
    var CloudPush = require('ti.cloudpush');
     var deviceToken = null;
    // Initialize the module android
    CloudPush.retrieveDeviceToken({
        success: deviceTokenSuccess,
        error: deviceTokenError
    });

// Enable push notifications for this device
// Save the device token for subsequent API calls and show a token in application
function deviceTokenSuccess(e) {
    deviceToken = e.deviceToken;

}
function deviceTokenError(e) {
    alert('Failed to register for push notifications!' + e.error);
}
CloudPush.setEnabled(true);
// Process incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
    try{
    Ti.API.log(JSON.stringify(evt));    
    var arr_from_json = JSON.parse(evt.payload); 

    var dialog = Ti.UI.createAlertDialog({
    message : arr_from_json['android'].alert,
    ok : 'OK',
    title : arr_from_json['android'].title
}).show();

   }
    catch(ex)
        {
            Ti.API.log(JSON.stringify(ex, null, 4));
        }

});

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)');
});

}

i can't receive notification on my device
Why?

HELP!!


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>