3

i want to open a certain page in the app when i click on notification in titanium i'm using titanium SDK 3.5.1 i have created an intent that lanch the app but it open the index page

var intent1 = Ti.Android.createIntent({
    flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
    className : 'co.ntime.audioPlayer.AudioplayerActivity',
    action : Ti.Android.ACTION_MAIN
});
var pending1 = Ti.Android.createPendingIntent({
    activity : Ti.Android.currentActivity,
    intent : intent1,
    type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
    flags : Titanium.Android.FLAG_ACTIVITY_NEW_TASK
});
Ti.Android.currentActivity.addEventListener('newintent', function(e) {
    Ti.API.info('caught intent!');
    var page1 = Alloy.createController('page1').getView();
    $.index.add(page1);
});

but it doesn't enter the new intent event

4 Answers4

0

You have to send extra field as string in your pushnotification which you can check onMessage() method then based on that extra field string you can set the Activity class using if else.

Pankaj
  • 7,908
  • 6
  • 42
  • 65
0

On my projects i added extra field on my push notification eg. pushID. This field is then read when opening the notification and depending on that field's value, the specific page is opened corresponding that value.

ex. pushID = 1, visit login page ex2. pushID =2, visit contacts page and so on...

MetaSnarf
  • 5,857
  • 3
  • 25
  • 41
0

i found an answer here is code

var intent1 = Ti.Android.createIntent({
    flags : Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
    className : 'co.ntime.audioPlayer.AudioplayerActivity',
    action : 1
});
intent1.putExtra('button', 'my first activity');
var pending1 = Ti.Android.createPendingIntent({
    activity : Ti.Android.currentActivity,
    intent : intent1,
    type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
    flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK
});
Ti.Android.currentActivity.addEventListener('newintent', function(e) {
    Ti.API.info('caught intent!');
     var page1 = Alloy.createController('page1').getView();
     $.index.open();
     $.index.add(page1);
     anAudioPlayer.pause();
});
0

Try this

var theNextWindow = Alloy.createController("PageName");
Alloy.Globals.pageStack.open(theNextWindow.getView());
S M
  • 3,133
  • 5
  • 30
  • 59
iissa
  • 1
  • 2