jkSSH2: android.os.NetworkOnMainThreadException

Discussion in 'Android Questions' started by devcitizen, Dec 21, 2012.

  1. devcitizen

    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
     
  2. ribber

    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!
     
    luke2012 likes this.
  3. devcitizen

    devcitizen New Member Licensed User

    Hallo Ribber!

    That is very kind of you!


    Please have a look at http://www.basic4ppc.com/forum/basi...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
     
  4. warwound

    warwound Expert Licensed User

  5. ribber

    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: Dec 26, 2012
  6. devcitizen

    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
     
  7. devcitizen

    devcitizen New Member Licensed User

    @Ribber: Please have a look at the project and screenshot I attached. Is this sufficient for your test?

    Thank you! Bye
    Roland
     

    Attached Files:

  8. ribber

    ribber Member Licensed User

    Thank you, this is sufficient. I will make some tests and improvements.
     
  9. Latzen

    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
     
  10. hayderOICO

    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?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    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
     
  12. hayderOICO

    hayderOICO Member Licensed User

    Thanks Erel!

    will give that a try.
     
  13. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    Hello Erel,
    please can you explain me, what does this code do?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice