Try this..
TextView txt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView) findViewById(R.id.text);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
new DownloadText("http://www.edumobile.org/android/").executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new String[]{null});
else
new DownloadText("http://www.edumobile.org/android/").execute(new String[]{null});
}
public class DownloadText extends AsyncTask<String, Void, String> {
// variables passed in:
String urls;
// constructor
public DownloadText(String urls) {
this.urls = urls;
}
@Override
protected void onPreExecute() {
pDialog = ProgressDialog.show(httpsData.this, "Fetching Details..", "Please wait...", true);
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
int BUFFER_SIZE = 2000;
InputStream in = null;
try {
InputStream in = null;
int response = -1;
URL url = new URL(urls);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
{
throw new IOException("Not an HTTP connection");
}
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return "";
}
InputStreamReader isr = new InputStreamReader(in);
int charRead;
String str = "";
char[] inputBuffer = new char[BUFFER_SIZE];
try {
while ((charRead = isr.read(inputBuffer))>0)
{
//---convert the chars to a String---
String readString = String.copyValueOf(inputBuffer, 0, charRead);
str += readString;
inputBuffer = new char[BUFFER_SIZE];
}
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
@Override
protected void onPostExecute(String result) {
// Now we have your JSONObject, play around with it.
if (pDialog.isShowing())
pDialog.dismiss();
if(!result.equals(""))
txt.setText(result);
}
}