Last active
December 16, 2015 04:19
-
-
Save mattaebersold/5375959 to your computer and use it in GitHub Desktop.
My attempt at creating a scheduled notification in Android
This file contains 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
function scheduleNotification(sound, message, hour, min) { | |
//create a new date, and then set the hours and minutes to what the user has set the alarm to be | |
var d = new Date(); | |
d.setHours(hour); | |
d.setMinutes(min); | |
d.setSeconds(0); | |
//cancel all existing notifications <><><><><><><><><<><><><><><><><> | |
clearAllNotifications(); | |
//create the 'intent' <><><><><><><><><<><><><><><><><> | |
var intent = Ti.Android.createIntent({ | |
flags : Titanium.Android.FLAG_ACTIVITY_CLEAR_TOP | Titanium.Android.FLAG_ACTIVITY_SINGLE_TOP, | |
className : 'ti.modules.titanium.ui.TiTabActivity', | |
packageName : Ti.App.id | |
}); | |
//create the 'pending intent' <><><><><><><><><<><><><><><><><> | |
var pendingIntent = Ti.Android.createPendingIntent({ | |
activity: Ti.Android.currentActivity, | |
intent: intent, | |
type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY, | |
flags: Titanium.Android.FLAG_CANCEL_CURRENT | |
}); | |
// The actual notification with properties <><><><><><><><><<><><><><><><><> | |
var notification = Ti.Android.createNotification({ | |
contentTitle : 'Good Morning STL', | |
contentText : message, | |
icon : Ti.App.Android.R.drawable.appicon, | |
when : d, //THIS IS SET UP TOP | |
contentIntent : pendingIntent, | |
defaults: Titanium.Android.DEFAULT_VIBRATE | |
}); | |
// This is where I fire the notification <><><><><><><><><<><><><><><><><> | |
Ti.Android.NotificationManager.notify(1, notification); | |
} | |
// Clear all the notifications that are present, so that they don't stack up | |
function clearAllNotifications() { | |
Ti.Android.NotificationManager.cancelAll(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment