-
-
Save muka/4cb123f9857da5b46c42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.createWindow({ | |
backgroundColor: 'blue' | |
}); | |
var btn = Ti.UI.createButton({ | |
title : 'Add Notification' | |
}); | |
btn.addEventListener('click', function(e) { | |
var activityName = Ti.App.name; | |
activityName= activityName.toUpperCase().substr(0,1) + activityName.toLowerCase().substr(1) + 'Activity'; | |
var className= Ti.App.id + '.' + activityName; | |
var activity = Ti.Android.currentActivity; | |
var intent = Ti.Android.createIntent({ | |
action: Ti.Android.ACTION_MAIN, | |
// className and packageName can be found by looking in the build folder | |
// for example, mine looked like this | |
// build/android/gen/com/appcelerator/test/Test7Activity.java | |
className : className, | |
packageName : Ti.App.id, | |
flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP | |
}); | |
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER); | |
var pending = Ti.Android.createPendingIntent({ | |
activity : activity, | |
intent : intent, | |
type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY, | |
flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY | |
}); | |
var ts = new Date().getTime()+5000000; | |
var notification = Ti.Android.createNotification({ | |
contentIntent : pending, | |
contentTitle : 'Test', | |
contentText : 'test', | |
tickerText : 'This is a test', | |
// when will only put the timestamp on the notification and nothing else. | |
// Setting it does not show the notification in the future | |
when : ts, | |
icon : Ti.App.Android.R.drawable.appicon, | |
flags : Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS | |
}); | |
Ti.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