I want to read the content of a URL with the following code :
myUrl=new URL(url);
stream=myUrl.openStream();
but the second line of code triggers an “android.os.NetworkOnMainThreadException” without any other explanation.
I work under Androïd 4 and I can add this code used to work with Androïd 2.3.3.
Any idea?
Thanks in advance for the time you will spend trying to help me.
So problem is that application attempts to perform a networking operation on main thread and this is not allowed.
For your goal i recommend to you use
AsyncTaskand do your work in backgroundThread.Here is example from my little app:
Or here is similar topic:
Download a file with Android, and showing the progress in aProgressDialog