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

Android: trayClickFocusedApp event not fired when push notification clicked in tray

$
0
0

Does anyone know how to get the trayClickFocusedApp event to fire reliably?

The code below is for a simple app.js test where a single window is opened, a push notification is fired off and then the app is placed into the background (simulated by launching the browser). If the app never opened a window, everything works as expected. However, if there is a window opened in the app, I do not get the trayClickFocusedApp event when returning from the background via tapping on a push notification.

Steps to reproduce

  1. Create a cloud enabled app
  2. Paste the following into app.js
    var win = Titanium.UI.createWindow({
        title: 'Push Test',
        backgroundColor: '#fff'
    });
     
    var login = ""; // Replace with an ACS user login
    var password = ""; // Replace with an ACS user password
     
    // If you comment out this line, everything works as expected
    win.open();
     
     
     
    // ------------------------------------------------------
    //
    // Push notification stuff
    //
    // ------------------------------------------------------
     
    var CloudPush = require('ti.cloudpush');
    CloudPush.debug = true;
    CloudPush.enabled = true;
     
    var deviceToken;
    var Cloud = require('ti.cloud');
     
    CloudPush.retrieveDeviceToken({
        success: function deviceTokenSuccess(e) {
            Ti.API.info('Device Token: ' + e.deviceToken);
            deviceToken = e.deviceToken;
            loginDefault(deviceToken);
        },
        error: function deviceTokenError(e) {
            Ti.API.error('Failed to register for push! ' + e.error);
        }
    });
     
    function loginDefault(e) {
     
        Cloud.Users.login({
            login: login,
            password: password
        }, function(e) {
            if (e.success) {
     
                defaultSubscribe();
     
                //Place app in background
                Ti.Platform.openURL("http://www.appcelerator.com");
     
                //Send a push in 2 seconds
                setTimeout(function() {
                    Cloud.PushNotifications.notify({
                        channel: 'message',
                        payload: {
                            "badge": 2,
                            "sound": "default",
                            "alert": "Push Notification Test",
                            "icon": "app_icon"
                        }
                    }, function(e) {
                        if (e.success) {
                            Ti.API.info('Success notify');
                        } else {
                            Ti.API.error('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
                        }
                    });
                }, 2000);
            } else {
                Ti.API.error('Error:\\n' + ((e.error && e.message) || JSON.stringify(e)));
            }
        });
     
    }
     
    function defaultSubscribe() {
     
        Cloud.PushNotifications.subscribe({
            channel: 'message',
            device_token: deviceToken,
            type: 'gcm'
        }, function(e) {
            if (e.success) {
                Ti.API.info('Subscribed!');
     
                CloudPush.addEventListener('callback', function(evt) {
                    Ti.API.info("callback" + JSON.stringify(evt));
                    alert('got the callback event');
                });
     
                CloudPush.addEventListener('trayClickFocusedApp', function(evt) {
                    Ti.API.info('Tray Click Focused App (app was already running)' + JSON.stringify(evt));
                    alert('got the trayClickFocusedApp event')
                });
            } else {
                Ti.API.error('Error:' + ((e.error && e.message) || JSON.stringify(e)));
            }
        });
    }
  3. Set your login/password to a valid user
  4. Launch the app on a device. The app should launch, fire off a push notification then go into the background by launching the browser.
  5. Tap the notification to return to the app.

Expected Results

The trayClickFocusedApp event listener should run and display a message.

Actual Results

The trayClickFocusedApp event listener does not run.

More info

If you comment out the line that opens the window and run the test again, everything works as expected.

Environment etc.

  • CLI version 3.2.0-cr3, Titanium SDK version 3.2.0.v20131218153242
  • Nexus S
  • Android 4.1.2
  • Mac OS X 10.8.5

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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