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.
Dim Phone As Phone
aver=Phone.SdkVersion
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
If Provider.IsInitialized=False Then Provider.Initialize
xtimer.Initialize("xtimer",20000)
If Main.secureit=True Then
mytimer.Initialize("mytimer",5000)
End If
End Sub
Sub Service_Start (StartingIntent As Intent)
If onlyonetime=0 Then
StartForegroundWithType("...")
n.Initialize("default", Application.LabelName, "LOW").AutoCancel(True).SmallIcon(LoadBitmap(File.DirAssets,"icon4app.png"))'.LargeIcon(LoadBitmap(File.DirAssets,"icon2.png"))
n.Build("ggg", "Η εφαρμογή εκτελείται!", "tag1", Main).Notify(1)
shownot=True
xtimer.Enabled=True
If Main.secureit=True Then
mytimer.Enabled=True
End If
End If
onlyonetime=1
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 False
End Sub
Sub delayedstops
If Main.isexited=False Then
Main.isexited=True
xtimer.Enabled = False
mytimer.Enabled = False
ToastMessageShow("Η εφαρμογή θα κλείσει...",True)
' Stop manual foreground mode (and remove the notification)
If shownot=True Then
started=0
Service.StopForeground(51042)
Sleep(500)
' Cancel any future scheduled starts
CancelScheduledService(Me)
Sleep(500)
End If
CallSubDelayed2(Main, "ServiceStopped", "gggService")
End If
End Sub
Sub Service_Destroy
If Main.isexited=False Then
If shownot=True Then
started=0
CallSubDelayed(Me,"delayedstops")
End If
End If
End Sub
Sub CreateNotification (Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon2"
notification.SetInfo("ggg", Body, Main)
Return notification
End Sub
Sub StartForegroundWithType(notif As Notification)
Dim oContext As JavaObject
Dim serviceType As Int = 1
Dim RunningPhone As Phone
oContext.InitializeContext
If RunningPhone.SdkVersion >= 29 And RunningPhone.SdkVersion<35 Then
Try
oContext.RunMethod("startForeground", Array As Object(1, CreateNotification(notif), serviceType))
started=1
Catch
Log(LastException)
Service.StartForeground(1, notif)
started=1
End Try
Else
Service.StartForeground(1, CreateNotification(notif))
started=1
End If
End Sub