Search code examples
titaniumtitanium-mobiletitanium-alloytitanium-modules

Titanium- Open URL when click on notification


I am stuck to get the click event of notification (android notification area), actually i want to open web page when user click on the notification.

here is my code,

var intent = Ti.Android.createIntent({
        flags : Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK,
        data : 'http://www.google.com',
        //url : 'http://www.google.com',
        className : 'com.android.browser.BrowserActivity',
        packageName : 'com.android.browser'
    });
    intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);

    var pending = Ti.Android.createPendingIntent({
        activity : Ti.Android.currentActivity,
        intent : intent,
        type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
        flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY
    });
    var dateValue = new Date();
    var notification = Ti.Android.createNotification({
        contentIntent : pending,
        contentTitle : Title,
        contentText : Message,
        tickerText : Title,
        when : dateValue.getTime(),
        icon : Ti.App.Android.R.drawable.appicon,
        flags : Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS,
        sound : Ti.Filesystem.getResRawDirectory() + 'notification.wav',
    });
    Ti.Android.NotificationManager.notify(1, notification);

Solution

  • This one of @phil worked for me: https://github.com/foolprooflabs/AndroidNotificationsCustomActivity

    But I've switched to gcm.js, because it's much more reliable. http://iamyellow.net/post/40100981563/gcm-appcelerator-titanium-module