function AndroidNotificationRegistration() { // Require in the module var CloudPush = require('ti.cloudpush'); var deviceToken = null; // Initialize the module CloudPush.retrieveDeviceToken({ success: deviceTokenSuccess, error: deviceTokenError }); // Enable push notifications for this device // Save the device token for subsequent API calls function deviceTokenSuccess(e) { CloudPush.enabled = true; deviceToken = e.deviceToken; Ti.App.Properties.setString("push_token", deviceToken); console.log("Android Push Token GET success."); } function deviceTokenError(e) { alert('Failed to register for push notifications! ' + e.error); } // Process incoming push notifications CloudPush.addEventListener('callback', function (evt) { //alert(evt.payload); var payload = JSON.parse(evt.payload); console.log("Received Notification " + evt.payload); if (evt.payload) { if (pushDialog != null) pushDialog.hide(); pushDialog = Ti.UI.createAlertDialog({ message : payload.android.alert, ok : 'Okay', title : (payload.android.title || 'Notification') }); pushDialog.addEventListener("click", function() { pushDialog.hide(); }); pushDialog.show(); } }); // Triggered when the push notifications is in the tray when the app is not running CloudPush.addEventListener('trayClickLaunchedApp', function (evt) { Ti.API.info('Tray Click Launched App (app was not running)'); }); // Triggered when the push notifications is in the tray when the app is running CloudPush.addEventListener('trayClickFocusedApp', function (evt) { Ti.API.info('Tray Click Focused App (app was already running)'); }); } AndroidNotificationRegistration();