P porkynet Member Licensed User Longtime User Jun 14, 2012 #1 Hello, I have basic program with this code and it's working. Code: Copy If HttpUtils.IsSuccess(MainUrl) = False Then Label1.Text = "" MainUrl = "http://somepage.com/id/" & Rnd(1,9188563) HttpUtils.Download("GET Job1", MainUrl) 'start End If (When url is bad app starts GET Job 1 again searching till it finds correct url.) Problem starts when i add this to manifest. Code: Copy android:targetSdkVersion="14" The app just crash, don't know why
Hello, I have basic program with this code and it's working. Code: Copy If HttpUtils.IsSuccess(MainUrl) = False Then Label1.Text = "" MainUrl = "http://somepage.com/id/" & Rnd(1,9188563) HttpUtils.Download("GET Job1", MainUrl) 'start End If (When url is bad app starts GET Job 1 again searching till it finds correct url.) Problem starts when i add this to manifest. Code: Copy android:targetSdkVersion="14" The app just crash, don't know why
P porkynet Member Licensed User Longtime User Jun 14, 2012 #2 This is logfile, but I repeat it works normal with old Android. Code: Copy Starting Job: GET Job1 ** Activity (main) Resume ** ** Service (httputilsservice) Create ** ** Service (httputilsservice) Start ** Error. Url=http://somepage.com/id/3277185 Message=Not Found httputilsservice_hc_responseerror (java line: 118) android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084) at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:151) at libcore.io.IoBridge.recvfrom(IoBridge.java:503) at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488) at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46) at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103) at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134) at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:161) at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159) at java.io.InputStreamReader.read(InputStreamReader.java:244) at java.io.Reader.read(Reader.java:145) at org.apache.http.util.EntityUtils.toString(EntityUtils.java:135) at anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper.GetString(HttpClientWrapper.java:464) at anywheresoftware.b4a.samples.httputils.httputilsservice._hc_responseerror(httputilsservice.java:118) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:145) at anywheresoftware.b4a.BA$3.run(BA.java:279) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4340) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Upvote 0
This is logfile, but I repeat it works normal with old Android. Code: Copy Starting Job: GET Job1 ** Activity (main) Resume ** ** Service (httputilsservice) Create ** ** Service (httputilsservice) Start ** Error. Url=http://somepage.com/id/3277185 Message=Not Found httputilsservice_hc_responseerror (java line: 118) android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084) at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:151) at libcore.io.IoBridge.recvfrom(IoBridge.java:503) at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488) at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46) at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103) at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134) at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:161) at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159) at java.io.InputStreamReader.read(InputStreamReader.java:244) at java.io.Reader.read(Reader.java:145) at org.apache.http.util.EntityUtils.toString(EntityUtils.java:135) at anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper.GetString(HttpClientWrapper.java:464) at anywheresoftware.b4a.samples.httputils.httputilsservice._hc_responseerror(httputilsservice.java:118) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:145) at anywheresoftware.b4a.BA$3.run(BA.java:279) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4340) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method)
Erel B4X founder Staff member Licensed User Longtime User Jun 14, 2012 #3 Note that you do not need to set the targetSdkVersion in order to support Android 4 devices. In order to avoid this error you should comment this logging line (hc_ResponseError): Code: Copy Log(Response.GetString("UTF8")) Upvote 0
Note that you do not need to set the targetSdkVersion in order to support Android 4 devices. In order to avoid this error you should comment this logging line (hc_ResponseError): Code: Copy Log(Response.GetString("UTF8"))
P porkynet Member Licensed User Longtime User Jun 14, 2012 #4 Thanks, it's working and not crashing now! But then why my android didn't show ICS style without this? Code: Copy android:targetSdkVersion="14" Upvote 0
Thanks, it's working and not crashing now! But then why my android didn't show ICS style without this? Code: Copy android:targetSdkVersion="14"
Erel B4X founder Staff member Licensed User Longtime User Jun 14, 2012 #5 If you want to use the ICS style then you need to set this attribute. Upvote 0
M mutleyMcladd New Member Licensed User Longtime User Jun 21, 2012 #6 I have the same issue trying to use Response.GetString("UTF8") with ICS I want to use the ICS Style as this is an internal app which will always run on the same device (ICS) so have included the following code to the maniefest to force the style. Code: Copy android:targetSdkVersion="14" I need to parse the resultstring from the following HTTPClient call but including the above forces an error. Is this function not available in ICS ? Code: Copy sub Main_ResponseSuccess (Response As HttpResponse, TaskId As Int) Dim resultString As String Log("ID=" & TaskId & " Response = " ) resultString = Response.GetString("UTF8") end sub Upvote 0
I have the same issue trying to use Response.GetString("UTF8") with ICS I want to use the ICS Style as this is an internal app which will always run on the same device (ICS) so have included the following code to the maniefest to force the style. Code: Copy android:targetSdkVersion="14" I need to parse the resultstring from the following HTTPClient call but including the above forces an error. Is this function not available in ICS ? Code: Copy sub Main_ResponseSuccess (Response As HttpResponse, TaskId As Int) Dim resultString As String Log("ID=" & TaskId & " Response = " ) resultString = Response.GetString("UTF8") end sub
Erel B4X founder Staff member Licensed User Longtime User Jun 21, 2012 #7 When you set targetSdkVersion=14 Android doesn't allow you to do any communication on the main thread. I recommend you to use HttpUtils as described above. If not you should use Response.GetAsynchronously instead of GetString. Upvote 0
When you set targetSdkVersion=14 Android doesn't allow you to do any communication on the main thread. I recommend you to use HttpUtils as described above. If not you should use Response.GetAsynchronously instead of GetString.