How to open a specific window after clicking on a notification in titanium

I want to open a specific page in the app, when I click on the notification in titanium I am using titanium SDK 3.5.1 I created an intent that pauses the application but it opens 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 introduce a new intent event

+3
android ios titanium localnotification


source to share


5 answers


You can try this



NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notif = new Notification(com.project.R.drawable.app_icon, "heading title", System.currentTimeMillis());
CharSequence from = "application name";
CharSequence message = "message which you want to show";

intent = new Intent(MyActivity.this,ShowActivity.class);
intent.putExtra("NotifID", notifID);
 pendingIntent= PendingIntent.getActivity(MyActivity.this, notifID, intent,     PendingIntent.FLAG_UPDATE_CURRENT| PendingIntent.FLAG_ONE_SHOT);

notif.setLatestEventInfo(this, from, message, intent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notif.vibrate = new long[] { 100, 250, 100, 500 };
nm.notify(notifID, notif);
finish();

      

0


source to share


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



0


source to share


In my projects, I have added an extra field to my push notification, eg. pushID. This field is then read when the notification is opened and the corresponding page is opened based on this field value.

ex. pushID = 1, visit the ex2 login page. pushID = 2, visit contact page, etc.

0


source to share


I found the answer, here is the 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


source to share


try it

var theNextWindow = Alloy.createController("PageName");
Alloy.Globals.pageStack.open(theNextWindow.getView());

      

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics