[TIMOB-18125] Android: CloudPush - trayClickLaunchedApp event not fired if listener added after window is open
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Jon Alter |
Assignee | Unknown |
Created | 2014-12-02T23:11:50.000+0000 |
Updated | 2019-04-09T23:15:35.000+0000 |
Description
When an app using cloudpush is killed, a push received, and the tray notification clicked, there are two events that fire.
callback
trackClickLaunchedApp
Both event get fired as they should if the event listeners are added before any window is opened. If you wait for the window to open then thetrackClickLaunchedApp
event does not get fired.
This happens because PROPERTY_TRAY_LAUNCHED_APP is added to the launch intent. When the event listener is added, the current activity is checked for the PROPERTY_TRAY_LAUNCHED_APP boolean and if it is found then the event is fired. If the event listener is added before a window is opened, it works fine because the current activity is the root activity and the intent has the property. However, once the new window is open, the activity returned by getActivity() is not the root activity, but the current activity that does not have the property set.
Steps to reproduce:
Run the example code below
Ensure that you are able to receive a push
Hit the back button to kill the app
Send a push
Click on the notification to launch the app
Notice that only one of the alerts (callback) is displayed, trayClickLaunchedApp is never fired
var win = Ti.UI.createWindow({
backgroundColor : '#ccc',
title : 'Android Cloud Push Notification'
});
var CloudPush = require('ti.cloudpush');
CloudPush.debug = true;
CloudPush.enabled = true;
CloudPush.singleCallback = true;
var deviceToken=null;
var Cloud = require('ti.cloud');
Cloud.debug = true;
var submit = Ti.UI.createButton({
title : 'Register For Push Notification',
color : '#000',
height : 60,
width : 200,
top : 100,
});
win.add(submit);
submit.addEventListener('click', function(e) {
loginDefault();
});
CloudPush.retrieveDeviceToken({
success : deviceTokenSuccess,
error : deviceTokenError
});
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
// Process incoming push notifications
var listenersAdded = false;
win.addEventListener('open', function() {
if (listenersAdded) {
return;
}
// Process incoming push notifications
CloudPush.addEventListener('callback', function(evt) {
alert("Notification received: " + evt.payload);
Ti.API.info("-------> Notification received: " + evt.payload);
});
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
alert('Tray Click Launched App (app was not running)');
Ti.API.info('-------> Tray Click Launched App (app was not running)');
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
alert('Tray Click Focused App (app was already running)');
Ti.API.info('-------> Tray Click Focused App (app was already running)');
});
listenersAdded = true;
});
function loginDefault(e) {
// At first you need to create an user from the application dashboard
// Then login that email and password
Cloud.Users.login({
login : 'sliang@appcelerator.com',
password : '1234'
}, function(e) {
if (e.success) {
alert("login success");
defaultSubscribe();
} else {
alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
function defaultSubscribe() {
Cloud.PushNotifications.subscribe({
channel : 'Android Test',
device_token : deviceToken,
type : 'gcm'
}, function(e) {
if (e.success) {
alert('Subscribed for Push Notification!');
} else {
alert('Error:' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
win.open();
Any progress/ETA on this?
On SDK 6.0.1 ti.cloud 3.2.9, 3.2.10, and 3.2.11 ti.cloudpush 4.0.3 trayClickLaunchedApp and trayClickFocusedApp not fired. I have played around with the settings as describe in [here](http://docs.appcelerator.com/platform/latest/#!/api/Modules.CloudPush) var CloudPush = require('ti.cloudpush'); CloudPush.debug = true; CloudPush.enabled = true; //default is true CloudPush.showTrayNotification = true; //default is true CloudPush.showTrayNotificationsWhenFocused = true; CloudPush.focusAppOnPush = true; //default is false CloudPush.singleCallback = true; //default is false Cloud.debug = true; Please advice
I am also having this same issue. Has there been any update to it?