syed
- Forum posts: 3
Aug 16, 2016, 7:39:31 AM via Website
Aug 16, 2016 7:39:31 AM via Website
protected String doInBackground(Void... params) {
String data = getData();
// TODO Auto-generated method stub
return data;
}
public String getData(){
// Connect and get a streams
InputStream inputStream = null;
String data = null;
try {
URL url = new URL(address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
inputStream = new BufferedInputStream(con.getInputStream());
BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer stringBuffer = new StringBuffer();
if(bufReader!= null){
while ((data=bufReader.readLine()) != null) {
stringBuffer.append(data+"\n");
}
}else {
return null;
}
return stringBuffer.toString();
}catch(MalformedURLException e){
e.printStackTrace();
Log.e(" error while reaading1",Log.getStackTraceString(e));
}catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
Log.e(" error while reaading2",Log.getStackTraceString(e));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Log.e(" error while reaading3",Log.getStackTraceString(e));
} finally{
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(" error while reaading4",Log.getStackTraceString(e));
}
}
}
return null;
}
— modified on Aug 17, 2016, 7:37:23 AM
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.