The code below ties up to the HTTP library. The files are correctly downloaded with an Android 6.0 phone, but produce a "Forbidden" or "Phone offline" error message with Anroid 4.x and 5.x. The remote server is online. My user says it did work before with Android 5.1 in that I am at a loss. Using B4A Ver 6.5 target Sdk=19.
If I am using obsolete or depreciated code it should not work with the latest Android version.
If I am using obsolete or depreciated code it should not work with the latest Android version.
B4X:
#Region Module Attributes
#StartAtBoot: False
#End Region
'Service module
Sub Process_Globals
Dim hc As HttpClient
End Sub
Sub Service_Create
hc.Initialize("hc")
End Sub
Sub Service_Start'(StartingIntent As Intent)
Dim Request1 As HttpRequest
Request1.InitializeGet("http://sdo.gsfc.nasa.gov/assets/img/latest/latest_1024_HMII.jpg")
hc.Execute(Request1, 0)
Dim Request2 As HttpRequest
Request2.InitializeGet("http://sdo.gsfc.nasa.gov/assets/img/latest/latest_1024_0304.jpg")
hc.Execute(Request2, 1)
End Sub
Sub Service_Destroy
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Response.GetAsynchronously("ImageResponse", File.OpenOutput(File.DirInternal, TaskId, False), True, TaskId)
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If StatusCode = -1 Then Reason = "Phone is offline"
ToastMessageShow(Reason ,False)
If Response <> Null Then Response.Release
ProgressDialogHide
End Sub
Sub ImageResponse_StreamFinish (Success As Boolean, TaskId As Int)
If Success = False Then
ToastMessageShow(LastException.Message, False)
Return
End If
CallSub2(sunspots,"DownloadComplete", TaskId)
End Sub