Back

CreateNotification

Hello World
Content:
- Methods

The Notification object can be used to put messages in the notification drawer.

ntf = app.CreateNotification( options ) → app object: Notification

The “AutoCancel” option will automatically dismiss the notificatin if the user touches it. “FullScreen” tries to create a larger notification on the screen. And “OnGoing” makes the Notification closeable by your app only.

Use the SetMessage method to tell the object what to display
notify.SetMessage( ticker, title, text );
The Notify method tells it to send the notification:
notify.Notify( id );
When the user touches your notification, your app will come to the front, even if it was not running.

If you use more than one notification, app.GetNotifyId can be used to check which notification was pressed by the user.

Example - Notification

function OnStart()
{
    app.ShowPopup( "Sending notification" );
    notify = app.CreateNotification();
    notify.SetMessage( "Ticker", "Title", "Text" );
    notify.Notify( "testID" );
    setTimeout( cancel, 5000 );

}

function cancel()
{
    notify.Cancel( "testID" );
    app.ShowPopup( "Notification cancelled" );
}
    Copy     Copy All       Run      

Methods

The following methods are available on the Notification object:

Cancel( id )
GetType() → String: “Notification”
Notify( id )
String
Number: milliseconds
String:
  hexadecimal: “#rrggbb”, “#aarrggbb”
  colourName: “red”, “green”, ...
String: path to file ( “/absolute/...” or “relative/...” )
String: comma “,” separated: “Ongoing”, “AutoCancel”, “FullScreen”
String: “CheckPerms”
function( source, title, message, extra, type )
ntf.Cancel
Cancel a notification with a specific id.
ntf.GetType
Returns the control class name.
ntf.Listen
Listens for any notification the user gets. Requires notification access by granted by android.settings.ACTIONNOTIFICATIONLISTENER_SETTINGS.
ntf.Notify
Send the notification to the user.
ntf.SetLargeImage
Set an image which will be displayed bigger than usual.
ntf.SetLights
Activate the device notification LEDs.
ntf.SetMessage
Set notification texts.
ntf.SetOnNotify
Called when a notification has been intercepted.
ntf.SetSmallImage
Set a small image in your notification.