Search code examples
androidtitaniumpush-notificationappceleratorappcelerator-mobile

Appcelerator Titanium LocalNotification for Android


IS there any LocalNotification available in Android.(some thing similar to Titanium.App.iOS.scheduleLocalNotification)

I need some simple notification(like alert) for Android Platform, even if my application closed. Is it possible in Titanium?


Solution

  • In android you can also fire notification but it will not be shown as alert box. Instead it will be shown in notification area. Here is code snippet to to fire notification in android.

    alarmTimeIntent = Ti.Android.createIntent({
                    className: 'org.appcelerator.titanium.TiActivity',
                    packageName: 'package name here',
                    flags: Titanium.Android.FLAG_ACTIVITY_CLEAR_TOP | Titanium.Android.FLAG_ACTIVITY_SINGLE_TOP 
                });
    
                var alarmTimePendingIntent = Ti.Android.createPendingIntent({
                    activity: Ti.Android.currentActivity,
                    intent: alarmTimeIntent,
                    type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
                    flags: Titanium.Android.FLAG_CANCEL_CURRENT
                });
    
                var alarmTimeNotification = Titanium.Android.createNotification({
                    contentIntent: alarmTimePendingIntent,
                    contentTitle: 'Content Title Here',
                    tickerText: 'Ticker text here',
                    defaults:Titanium.Android.NotificationManager.DEFAULT_SOUND,
                    when: new Date()
                });
    
                Ti.Android.NotificationManager.notify(1, alarmTimeNotification);