jkSSH2: android.os.NetworkOnMainThreadException

devcitizen

New Member
Licensed User
Hi,

I am trying to find my way around ssh command execution using Ribber's jkSSH2 library version 1.10. The same NetworkOnMainThreadException (newer Android sdk levels will not permit networking in the main ui thread) is already fixed for the HttpUtils2 library. Is there any way for me to use jkSSH2 with API level > 8?

Thank you in advance!

Kind regards

Roland
 

ribber

Member
Licensed User
Hi,

I will try to update my libary to solve this problem. Could you give me some information how it was fixed in HttpUtils2?

Thanks!
 

devcitizen

New Member
Licensed User
Hallo Ribber!

I will try to update my libary to solve this problem.
That is very kind of you!


Could you give me some information how it was fixed in HttpUtils2?
Please have a look at http://www.basic4ppc.com/forum/basic4android-updates-questions/22546-my-librarie-no-work-targetsdkversion-14-a.html#post130993

I think it is quite a task, because the network interaction has to be placed in an extra thread to really fix this.

Kind regards

Roland
 

ribber

Member
Licensed User
Ok, thank you both.

@devcitizen: Could you please send me demo project (with the error) so I can test my updated libary?
 
Last edited:

devcitizen

New Member
Licensed User
Hallo Ribber,

sorry for my late answer. I will create a demo the next day. Thank you for your help!

Bye
Roland
 

Latzen

New Member
Licensed User
Hello, I have the same problem. The error get when you run the command on the server. If I execute ssh2.isconnected, the answer is false, but no errors when trying to connect. With Android 4.0 I have the problem with 2.3 no. you have discovered something?

Thanks
 

hayderOICO

Member
Licensed User
Hi All

Just to ping this thread. Is there any update to the SSH threading issue? I'm trying to make a small app which has multiple buttons each calling a different command on the PC via SSH.

Should I use the B4Aserver instead?
 

Erel

Administrator
Staff member
Licensed User
You can use B4AServer.

You can remove this error with this code:
B4X:
Dim p As Phone
If p.SdkVersion >= 9 Then
   Dim r As Reflector
   r.Target = r.CreateObject("android.os.StrictMode$ThreadPolicy$Builder")
   r.Target = r.RunMethod("permitAll")
   r.Target = r.RunMethod("build")
   r.RunStaticMethod("android.os.StrictMode", "setThreadPolicy", _
      Array As Object(r.Target), Array As String("android.os.StrictMode$ThreadPolicy"))
End If
 

imgsimonebiliato

Well-Known Member
Licensed User
You can use B4AServer.

You can remove this error with this code:
B4X:
Dim p As Phone
If p.SdkVersion >= 9 Then
   Dim r As Reflector
   r.Target = r.CreateObject("android.os.StrictMode$ThreadPolicy$Builder")
   r.Target = r.RunMethod("permitAll")
   r.Target = r.RunMethod("build")
   r.RunStaticMethod("android.os.StrictMode", "setThreadPolicy", _
      Array As Object(r.Target), Array As String("android.os.StrictMode$ThreadPolicy"))
End If
Hello Erel,
please can you explain me, what does this code do?
 
Top