Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim out As OutputStream
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
DownloadApk
End Sub
Sub Service_Destroy
End Sub
Sub DownloadApk
Dim hc As OkHttpClient
hc.InitializeAcceptAll("hc")
Dim req As OkHttpRequest
req.InitializeGet("http://xxxxxxxxxxxxxxxxxx")
hc.Execute(req, 1000)
End Sub
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
Log("apk size: " & Response.ContentLength)
Log("response code: " & Response.StatusCode)
Response.GetAsynchronously("res", File.OpenOutput(File.DirRootExternal&"/Download", "Observer.apk", False), True, TaskId)
End Sub
Sub res_StreamFinish (Success As Boolean, TaskId As Int)
Log($" ${Success}"$)
If Success Then
CallSubDelayed(Main, "InstallnewApk")
End If
End Sub
Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log($"Error: ${Response.ErrorResponse}, ${Reason}, ${StatusCode}"$)
If Response <> Null Then Response.Release
End Sub