Android Question [SOLVED] Problem: Widget using a Web Service does not run

Rene Barrera

Member
Licensed User
Longtime User
Hi, I know all of you are very busy, but i dare to distract you because this is ver important to me, so a beg to you to take a look to my problem and see if you can give me a suggestion.
The problem is that the code showed below is mounted in a service module so I can create a widget to get the weather from a web service. Is important to say that I implemented this code in a standar b4a application and it run correctly as espected, but now in the service module i can not get the same result
Don Manfred kindly suggested me to track the log, but i realy dont know how the log can be displayed from a widget. If more information is needed, please let me know.
Thanks in advance
B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

'Service module
Sub Process_Globals
 
    Dim rv As RemoteViews
    Dim HttpCli1 As HttpClient
 
    Dim URL As String
  Dim XML As String
    Dim Ciudad As String : Ciudad = "Acapulco"
    Dim Pais As String   : Pais = "Mexico"
 
End Sub
Sub Service_Create

    'Set the widget to update every 60 minutes.
    rv = ConfigureHomeWidget("lyoWeather", "rv", 60, "A-TIM-W-Clima")
    HttpCli1.Initialize ("HttpCli1")
'    ConsumirWebService
 
End Sub

Sub Service_Start (StartingIntent As Intent)

    Dim intCntr As Int
 
    If rv.HandleWidgetEvents(StartingIntent) Then Return
 

End Sub

Sub rv_RequestUpdate

    ConsumirWebService

End Sub

Sub ConsumirWebService()

    Dim Request As HttpRequest
     
    URL = "http://www.webservicex.net/globalweather.asmx"
 
    XML = XML & "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:web='http://www.webserviceX.NET'>"
    XML = XML & "<soap:Header/>"
    XML = XML & "<soap:Body>"
    XML = XML & "<web:GetWeather>"
    XML = XML & "<web:CityName>" & Ciudad & "</web:CityName>"
    XML = XML & "<web:CountryName>" & Pais & "</web:CountryName>"
    XML = XML & "</web:GetWeather>"
    XML = XML & "</soap:Body>"
    XML = XML & "</soap:Envelope>"
           
  Request.InitializePost2(URL, XML.GetBytes("UTF8"))
  Request.SetHeader("Content-Type", "application/soap+xml; charset=utf-8")                                                                 
  Request.Timeout = 6000000
  If HttpCli1.Execute(Request, 1) = False Then Return
    
    ProgressDialogShow("Esperando Respuesta...")
    
End Sub

Sub HttpCli1_ResponseSuccess (Response As HttpResponse, TaskId As Int)

    ProgressDialogHide
 
  Dim resultSoapXML As String
 
  resultSoapXML = Response.GetString("UTF8")
'  Msgbox(resultSoapXML,"")
 
    GetInfo(resultSoapXML)

End Sub

Sub HttpCli1_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int) 

    ProgressDialogHide
  Dim resultSoapXML As String
 
  resultSoapXML = Response.GetString("UTF8")

    Msgbox(resultSoapXML,"")

End Sub

Sub GetInfo(ResultSoapXML As String)

    Dim intFin As Int                                        'Indice del fin de búsqueda del string correspondiente
    Dim strResult As String                       'Trae inf del Resultado para validar si se tiene información
    Dim strLocation As String                     'Trae la Localidad
    Dim strTime As String                           'Trae la Hora
    Dim strWind As String                           'Trae el Viento
    Dim strVisibility As String               'Trae la Visibilidad
    Dim strSkyConditions As String           'Trae las condiciones del Cielo (Condición Amosférica)
    Dim strTemperature As String               'Trae la temperatura
    Dim strDewPoint As String                   'Trae el Punto de rocío (Humedad)
    Dim strRelativeHumidity As String   'Trae la Humedad Relativa
    Dim strPressure As String                    'Trae la Presión Atmosférica
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''INI - substrings para ir obteniendo la Información del Web Service del Clima'''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    'Valida si se tiene información para la localidad seleccionada
    strResult = ResultSoapXML.SubString(ResultSoapXML.IndexOf("<GetWeatherResult>")+ 18)
    intFin = strResult.IndexOf("</GetWeatherResult>")
    strResult = strResult.subString2(0, intFin)
 
    If strResult = "Data Not Found" Then
        ToastMessageShow ("No se tiene Información de Temperatura para " & Ciudad & "!", True)
        rv_Disabled
    End If

    'Localidad
    strLocation = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;Location&gt;")+ 16)
    intFin = strLocation.IndexOf("&lt;/Location&gt;")
    strLocation = strLocation.subString2(0, intFin)

    'Hora
    strTime = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;Time&gt;")+ 12)
    intFin = strTime.IndexOf("&lt;/Time&gt;")
    strTime = strTime.subString2(0, intFin)
 
    'Wind (Viento)
    strWind = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;Wind&gt;")+ 12)
    intFin = strWind.IndexOf("&lt;/Wind&gt;")
    strWind = strWind.subString2(0, intFin)
 
    'Visibility (Viibilidad)
    strVisibility = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;Visibility&gt;")+ 18)
    intFin = strVisibility.IndexOf("&lt;/Visibility&gt;")
    strVisibility = strVisibility.subString2(0, intFin)
 
    'SkyConditions (Condición Atmosférica)
    strSkyConditions = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;SkyConditions&gt;")+ 21)
    intFin = strSkyConditions.IndexOf("&lt;/SkyConditions&gt;")
    strSkyConditions = strSkyConditions.subString2(0, intFin)
 
    'Temperature (Temperatura)
    strTemperature = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;Temperature&gt;")+ 19)
    intFin = strTemperature.IndexOf("&lt;/Temperature&gt;")
    strTemperature = strTemperature.subString2(0, intFin)
 
    'DewPoint (Humedad)
    strDewPoint = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;DewPoint&gt;")+ 16)
    intFin = strDewPoint.IndexOf("&lt;/DewPoint&gt;")
    strDewPoint = strDewPoint.subString2(0, intFin)

    'Relative Humidity (Humedad relativa)
    strRelativeHumidity = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;RelativeHumidity&gt;")+ 24)
    intFin = strRelativeHumidity.IndexOf("&lt;/RelativeHumidity&gt;")
    strRelativeHumidity = strRelativeHumidity.subString2(0, intFin)
 
    'Pressure (presión Atmosférica)
    strPressure = ResultSoapXML.SubString(ResultSoapXML.IndexOf("&lt;Pressure&gt;")+ 16)
    intFin = strPressure.IndexOf("&lt;/Pressure&gt;")
    strPressure = strPressure.subString2(0, intFin)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''FIN - substrings para ir obteniendo la Información del Web Service del Clima'''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Set_Temperature

End Sub

Sub Set_Temperature

'    lblTemperature.Text = strTemperature
rv.SetText("lblTemperatura", "strTemperatura")

 
End Sub

Sub HttpClient1_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int) 

    ProgressDialogHide
  Dim resultSoapXML As String
 
  resultSoapXML = Response.GetString("UTF8")

    Msgbox(resultSoapXML,"")

End Sub

Sub rv_Disabled
    StopService("")
End Sub

Sub Service_Destroy

End Sub
 

Rene Barrera

Member
Licensed User
Longtime User
Hi Don,

Finally I got it, the widget works correctly, but must say that your help was so much useful.
This case is closed.

Thank you so much
 
Upvote 0

Rene Barrera

Member
Licensed User
Longtime User
Hi Erel,

Excuse me, for my mistake i was forgetting to thank to Erel, I must thank you too, your support was really important too

Thank you so much
 
Last edited:
Upvote 0
Top