Its because you're doing network operation on Main UI thread
if you're using threads to do network operations then you can use this code snippet
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy =
new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
in your OnCreate()
But its wrong practice to use above said operation, instead you should use AsyncTask
class provided by android to handle properly network operation without blocking UI thread
.
you can learn more by visiting this LINK
or can use the below code
private class UploadFiles extends AsyncTask<String, Void, Void> {
protected String doInBackground(String... urls) {
//THIS METHOD WILL BE CALLED AFTER ONPREEXECUTE
//YOUR NETWORK OPERATION HERE
return null;
}
protected void onPreExecute() {
super.onPreExecute();
//THIS METHOD WILL BE CALLED FIRST
//DO OPERATION LIKE SHOWING PROGRESS DIALOG PRIOR TO BEGIN NETWORK OPERATION
}
protected void onPostExecute(String result) {
super.onPostExecute();
//TNIS METHOD WILL BE CALLED AT LAST AFTER DOINBACKGROUND
//DO OPERATION LIKE UPDATING UI HERE
}
}
and you can simple call this class by writing
new UploadFiles ().execute(new String[]{//YOUR LINK});