var win = Ti.UI.createWindow({fullscreen:false});
//create some simple UI
var textfield = Ti.UI.createTextField({width:300, height:'auto', top:40, left:20, hintText:'enter message'});
var button = Ti.UI.createButton({title:'Send Notification', width:'auto', top:120, left:20, height:'auto'});
var label = Ti.UI.createLabel({width:'auto', top:200, left:20, height:'auto', width:200, text:'Message from intent:'});
var msgLabel = Ti.UI.createLabel({width:'auto', top:240, left:20, height:'auto', width:200, backgroundColor:'lightgrey', text:'---'});
win.add(textfield);
win.add(button);
win.add(label);
win.add(msgLabel);
win.addEventListener("open", function(evt) {
button.addEventListener("click", function(evt) {
//handle the pending intent from the notification bar
win.activity.addEventListener("newIntent", function(evt)
{
var pushObjStr = evt.intent.getStringExtra("pushReceived"); // ***** GET
if (pushObjStr) {
Ti.API.debug("received data: " + pushObjStr);
msgLabel.text = pushObjStr;
} else {
Ti.API.debug("no data received");
msgLabel.text = "no data received";
}
});
Ti.UI.Android.hideSoftKeyboard();
msgLabel.text = "---"; //reset any previous text value
//grab the user input
var message = textfield.value;
if (!message) {
alert('you must provide a message');
return;
} else {
//clear out what was typed
textfield.value = '';
}
//put some custom data into an intent
var intent = Ti.Android.createIntent(
{
action: Ti.Android.ACTION_MAIN,
flags: Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
className: "org.appcelerator.titanium.TiActivity",
packageName: Ti.App.id
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCH);
intent.putExtra("pushReceived", message); //***** PUT
//a pending intent to send open an activity when launched
var pending = Ti.Android.createPendingIntent(
{
activity: win.activity,
intent: intent,
//updateCurrentIntent: false,
type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY
});
//put a notification in the notification bar
var notification = Ti.Android.createNotification(
{
contentIntent: pending,
contentTitle: "New Notification",
contentText: "Msg: " + message,
tickerText: "New Notification"
});
Ti.Android.NotificationManager.notify(1, notification);
});
});
win.open();
1. Run the test case
2. Introduce a message in the textfield
3. Press the send button
Expected Result
After receiving the local notification the message textfield will throw the newIntent event and show the sent message or a "No data received" message
Actual Result
The newIntent event is not thrown
This is working as expected. You need to click on the notification for the pendingIntent to activate. Sending a notification by calling notify() alone does not trigger the pendingIntent. In this example, you would do: 1. Introduce a message in the textfield 2. Press the button 3. Click on the newly received notification. 4. New data received.
Closing ticket as invalid with reference to previous comments.