I need to execute third-party open source program, which throws NetworkOnMainThreadException. According to SDK reference, this is only thrown for applications targeting the
These are not solutions, you Just tell the tutelar to sleep and sill!!! the android decide not to let you make network operations in the main thread (UI thread), because of the "halts" that these operation can make (the ui stop respond). So, as I read, they tell you to not shoot your leg, and you find the way to do!!!
the solution : separated thread, Or Async ...
You could change it to:
android:targetSdkVersion="9"
API 10 corresponds to honeycomb, while 9 is gingerbread. This behavior is only seen in APIs 10 and above.
However, I would advise against this. Instead, you should move any long running operations, or operations with the possibility of running for long into a background thread, like an AsyncTask.
You could also try to set Strict Mode off using:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
You are performing network task on your UI Thread. The best way to perform network operation is to use AsyncTask or simply create another thread. However, if you want a quick and dirty way to get rid of the error; you can also use this
ThreadPolicy tp = ThreadPolicy.LAX;
StrictMode.setThreadPolicy(tp);