jkSSH2: android.os.NetworkOnMainThreadException

Status
Not open for further replies.

devcitizen

New Member
Licensed User
Longtime 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
 
Last edited by a moderator:
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!
 
Upvote 0
Upvote 0
Ok, thank you both.

@devcitizen: Could you please send me demo project (with the error) so I can test my updated libary?
 
Last edited:
Upvote 0
@Ribber: Please have a look at the project and screenshot I attached. Is this sufficient for your test?

Thank you! Bye
Roland
 

Attachments

  • jksshExample.zip
    jksshExample.zip
    2.6 KB · Views: 886
  • screenshot1.png
    screenshot1.png
    45.8 KB · Views: 1,126
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
You can use B4AServer.

You can remove this error with this code:
Code:
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
 
Upvote 0
You can use B4AServer.

You can remove this error with this code:
Code:
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?
 
Upvote 0
Check this post.
It will prevent the error and crash by allowing network on main.
 
Upvote 0
Status
Not open for further replies.
Back
Top