Skip to content

Instantly share code, notes, and snippets.

Created May 26, 2012 14:22
Show Gist options
  • Select an option

  • Save anonymous/2794118 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2794118 to your computer and use it in GitHub Desktop.
Android Notification
var win = Ti.UI.createWindow({
backgroundColor : 'gray'
});
var btn = Ti.UI.createButton({
title: 'Notification'
});
btn.addEventListener('click', function(e) {
alert('Bingo!');
var intent = Titanium.Android.createIntent({
action: Titanium.Android.ACTION_MAIN,
className: 'br.com.royalsoft.notificacao.NotificacaoActivity',
packageName: 'br.com.royalsoft.notificacao'
});
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);
var pending = Titanium.Android.createPendingIntent({
activity: Titanium.Android.currentActivity,
intent: intent,
type: Titanium.Android.PENDING_INTENT_FOR_ACTIVITY,
flags: Titanium.Android.FLAG_ACTIVITY_NEW_TASK
});
// Create the notification
var notification = Titanium.Android.createNotification({
// icon is passed as an Android resource ID -- see Ti.App.Android.R.
icon: Ti.App.Android.R.drawable.my_icon,
contentTitle: 'Something Happened',
contentText : 'Click to return to the application.',
contentIntent: pending
});
// Send the notification.
Titanium.Android.NotificationManager.notify(1, notification);
});
win.add(btn);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment