#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private nid As Int = 1
Private lock As PhoneWakeState
Private Radio As Bitmap
Private Icone1 As Bitmap
Private Icone2 As Bitmap
Private Icone3 As Bitmap
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
lock.PartialLock
Radio = LoadBitmapResize(File.DirAssets, "radio.png", 24dip, 24dip, False)
Icone1 = LoadBitmapResize(File.DirAssets, "play.png", 24dip, 24dip, False)
Icone2 = LoadBitmapResize(File.DirAssets, "stop.png", 24dip, 24dip, False)
Icone3 = LoadBitmapResize(File.DirAssets, "exit.png", 24dip, 24dip, False)
'Play
Service.StartForeground(nid, MediaStyle_Notification )
End Sub
Public Sub Jouer
Service.StopForeground(nid)
CallSub(Main,"Jouer")
End Sub
Public Sub Stop
Service.StopForeground(nid)
CallSub(Main,"Stop")
End Sub
Public Sub Quitter
Service.StopForeground(nid)
CallSub(Main,"Quitter")
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
If StartingIntent.IsInitialized Then
Dim cs As CSBuilder
cs.Initialize.Bold.Size(20).Append($"Action: ${StartingIntent.Action}"$).PopAll
Log(cs)
If StartingIntent.Action="Jouer" Then Jouer
If StartingIntent.Action="Stop" Then Stop
If StartingIntent.Action="Quitter" Then Quitter
End If
'Service.StopAutomaticForeground
End Sub
Sub MediaStyle_Notification As Notification
Dim n As NB6
n.Initialize("default", Application.LabelName, "LOW").SmallIcon (Radio)
n.AddButtonAction(Icone1, "Action 1", Me, "Jouer") 'use different bitmaps...
n.AddButtonAction(Icone2, "Action 2",Me, "Stop")
n.AddButtonAction(Icone3, "Action 3", Me, "Quitter")
n.MediaStyle
Return n.Build("", "", "tag", Me)
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
CallSub(Main,"Quitter")
lock.ReleasePartialLock
End Sub