[TIMOB-20111] Android: trayClickFocusedApp event not fired when push notification clicked in tray
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2016-04-19T06:25:23.000+0000 |
Affected Version/s | Release 5.1.1 |
Fix Version/s | n/a |
Components | Android |
Labels | android, pushnotification |
Reporter | Brad Ball |
Assignee | Srikanth Sombhatla |
Created | 2015-11-30T16:00:38.000+0000 |
Updated | 2016-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)));
}
});
}
[~bradleycorn], In the app.js L:53 when calling
Cloud.PushNotifications.notify
are you getting success response? Because that API expectsto_ids
. http://docs.appcelerator.com/arrowdb/latest/#!/api/PushNotifications-method-notify Once I change it to current logged-in userid, I am gettingtrayClickFocusedApp
event. Please verify and let me know. [~aislam] Please confirm.@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.