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:

ribber

Member
Licensed User
Longtime 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!
 
Upvote 0

devcitizen

New Member
Licensed User
Longtime User
Upvote 0

ribber

Member
Licensed User
Longtime 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:
Upvote 0

devcitizen

New Member
Licensed User
Longtime User
Hallo Ribber,

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

Bye
Roland
 
Upvote 0

devcitizen

New Member
Licensed User
Longtime User
@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
    2.6 KB · Views: 573
  • screenshot1.png
    screenshot1.png
    45.8 KB · Views: 634
Upvote 0

Latzen

New Member
Licensed User
Longtime 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
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime 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?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime 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?
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Check this post.
It will prevent the error and crash by allowing network on main.
 
Upvote 0
Status
Not open for further replies.
Top