Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20111] Android: trayClickFocusedApp event not fired when push notification clicked in tray

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionCannot Reproduce
Resolution Date2016-04-19T06:25:23.000+0000
Affected Version/sRelease 5.1.1
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, pushnotification
ReporterBrad Ball
AssigneeSrikanth Sombhatla
Created2015-11-30T16:00:38.000+0000
Updated2016-04-19T06:25:23.000+0000

Description

When a view is opened and app is placed into background, tapping on a push notification does not fire the trayClickFocusedApp event. This works fine if I don't open a window in the app. However, if even a single window is opened, trayClickFocusedApp stops working (I'm guessing this is due to the fact that there are more than a single activity if windows are opened). In the attached test code, simply comment out the following line and trayClickFocusedApp to start working again:
 win.open(); 
Steps to reproduce

Create a cloud enabled app

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

Set your login/password to a valid user (lines 6 & 7)

Launch the app on a device. The app should launch, fire off a push notification then go into the background by launching the browser.

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.

Comments

  1. Srikanth Sombhatla 2016-02-26

    [~bradleycorn], In the app.js L:53 when calling Cloud.PushNotifications.notify are you getting success response? Because that API expects to_ids. http://docs.appcelerator.com/arrowdb/latest/#!/api/PushNotifications-method-notify Once I change it to current logged-in userid, I am getting trayClickFocusedApp event. Please verify and let me know. [~aislam] Please confirm.
  2. Brad Ball 2016-03-01

    @Srikanth, Sorry, I posted a bad example. I DO get the trayClickFocusedApp event when running the sample above. I believe the issue (the event not getting fired) actually occurs when the app has more than one activity. I can put together a sample app to test and verify that, but it'll probably take a me a few weeks, because I'm swamped with other work at the moment. Again, sorry for the bad sample posted in the ticket.

JSON Source