You are accessing the network from Main Thread
. You have to do the network operation only in a background Thread
Use AsyncTask
like this
new AsyncTask<URL, Integer, Long>(){
@Override
protected Long doInBackground(URL... params) {
try {
// call you method here
} catch (Exception ex) {
// handle the exception here
}
return null;
}
}.execute();