#Region Service Attributes
#StartAtBoot: true
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ActMan As JavaObject
Dim R As Reflector
Dim versionandroid As String
Dim locked As Boolean = True
Dim lowtime = 5000, hitime = 10000, curtime=5000 As Int
Dim PackageName As String
Dim PE As PhoneEvents
Dim screenoff As Boolean=False
Dim SF As StringFunctions
End Sub
Sub Service_Create
Log("createservice")
PE.Initialize("PE")
'get version android
R.Target=R.GetContext
ActMan = R.RunMethod2("getSystemService","activity","java.lang.String")
versionandroid=R.GetStaticField ("android.os.Build$VERSION", "RELEASE")
End Sub
Sub Service_Start (StartingIntent As Intent)
Log("startservice")
StartServiceAt("", DateTime.Now + curtime, True)
If SF.Left(versionandroid,1)>=5 Then
Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningAppProcesses",Array As Object())
Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0))
PackageName = CompInfo.GetField("processName")
Else
Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningTasks",Array As Object(1))
Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0)).GetField("topActivity")
PackageName = CompInfo.RunMethod("getPackageName",Null)
End If
Log(PackageName&" estado: "&locked & "intervalo: "&curtime)
ToastMessageShow(PackageName&" estado: "&locked & "intervalo: "&curtime,False)
End Sub
Sub Service_Destroy
End Sub
Sub PE_ScreenOn (Intent As Intent)
Log("ScreenOn")
curtime=lowtime
StartServiceAt("", DateTime.Now + curtime, True)
locked=True
screenoff=False
End Sub
Sub PE_ScreenOff (Intent As Intent)
Log("ScreenOff")
curtime=hitime*60
locked=True
screenoff=True
End Sub
Sub PE_UserPresent (Intent As Intent)
Log("UserPresent")
End Sub