WM Android Notification - Push Notification
CODE INIT GLOBAL
// Global variables
gsNamePersistentThread is string = "PersistentNotifications"
gsPeriodicityPreference is string = "periodicity"
gsPreferenceNotificationsEnabled is string = "benabled"
gbActive is boolean = False
gnPeriodicity is int
// Notification that is displayed when the persistent thread is enabled
gPersistentNotification is a Notification
gPersistentNotification..ActivateApplication = True
gPersistentNotification..Message = "Persistent notifications enabled"
gPersistentNotification..Title = "Persistent notifications"
gPersistentNotification..Icon = "notif_persistent.png"
gSporadicNotification is a Notification
gSporadicNotification..ActivateApplication = True
gSporadicNotification..Deletable = True
gSporadicNotification..Icon = "notif.png"
gSporadicNotification..Sound = "notif.mp3"
IF InAndroidSimulatorMode() THEN
EndProgram("This example does not operate in Android simulator mode.","This application must be run on an emulator or on an Android device.")
END
--------------------------------------------------------------------------------------------------
INIT WINDOW
// Starts the notifications if necessary
gbActive = LoadParameter(gsPreferenceNotificationsEnabled,False)
IF gbActive THEN
ActivateApplications(True)
END
// Check whether the notifications are enabled
RefreshStatus()
---------------------------------------------------------------------------------------------------------------------------------
// Summary: Enable the notifications
// Syntax:
//ActivateApplications (<bActivate> is boolean)
//
// Parameters:
// bActivate (boolean): <specify the role of ManageNotifications>
// Return value:
// None
//
// Example:
// Indicate an example.
//
PROCEDURE ActivateApplications(bActivate is boolean)
IF bActivate THEN
// Enable the notifications
gbActive = True
SaveParameter(gsPreferenceNotificationsEnabled,True)
IF ThreadState(gsNamePersistentThread) = threadUnknown THEN
ThreadExecute(gsNamePersistentThread,threadGlobalContext,ManageNotifications)
ThreadPersistent(gsNamePersistentThread,gPersistentNotification)
ELSE
// The notifications are already enabled
END
ELSE
// Disable the notifications
gbActive = False
SaveParameter(gsPreferenceNotificationsEnabled,False)
NotifDelete(gSporadicNotification)
END
// Refreshes the status
RefreshStatus()
-----------------------------------------------------------------------------------------------------------------------
// Summary: Checks whether the notifications are enabled
//
PROCEDURE RefreshStatus()
IF LoadParameter(gsPreferenceNotificationsEnabled,False) THEN
gbActive = True
BTN_Validate = "Disable the notifications"
EDT_Periodocity..Visible = False
ELSE
gbActive = False
BTN_Validate = "Enable the notifications"
EDT_Periodocity..Visible = True
END
-----------------------------------------------------------------------------------------------------------------------------
// Summary: Displays a notification
//
PROCEDURE DisplayNotification()
sTime is string = TimeToString(TimeSys(),"HH:MM:SS")
NotifDelete(gSporadicNotification)
gSporadicNotification..Message = StringBuild("It is %1",sTime)
gSporadicNotification..DropDownText = sTime
gSporadicNotification..Title = sTime
NotifAdd(gSporadicNotification)
------------------------------------------------------------------------------------------------------------
// Summary: Manages the notifications in a persistent thread
//
PROCEDURE ManageNotifications()
WHILE gbActive
// Displays the notification
DisplayNotification()
// Wait during the periodicity
ChronoStart(1)
WHILE gbActive _AND_ ((ChronoValue(1) / 1000) < gnPeriodicity)
Multitask(50)
END
ChronoEnd(1)
END
-------------------------------------------------------------------------------------------------------------------