You will have to change the url to your personal url!
On Wed, Nov 21, 2012 at 2:41 PM, Παύλος-Πέτρος Τουρνάρης < [email protected]> wrote: > Καλησπέρα Αντώνη :P !!! > > private class RetrieveJsonInfo extends AsyncTask<String, Void, Object> { > > public String finalContent; > @Override > protected Boolean doInBackground(String... params) { > } > > public void getInfo() { > StringBuilder builder = new StringBuilder(); > HttpParams httpParameters = new BasicHttpParams(); > int timeoutConnection = 2000; > HttpConnectionParams.setConnectionTimeout(httpParameters, > timeoutConnection); > HttpClient client = new DefaultHttpClient(httpParameters); > HttpGet httpGet = new HttpGet("http://schedule.aueb.gr/mobile/index.php"); > try { > HttpResponse response = client.execute(httpGet); > StatusLine statusLine = response.getStatusLine(); > int statusCode = statusLine.getStatusCode(); > if (statusCode == 200) { // success! > HttpEntity entity = response.getEntity(); > InputStream content = entity.getContent(); > BufferedReader reader = new BufferedReader( > new InputStreamReader(content)); > String line; > while ((line = reader.readLine()) != null) { > builder.append(line); > } > finalContent = builder.toString(); > } else { > Log.i("error", "Failed to download file"); > } > } catch (ClientProtocolException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } catch (JSONException e) { > e.printStackTrace(); > } > > } > } > > Try using this code inside your Activity. The finalContent will be the > content of your file! > > > On Wed, Nov 21, 2012 at 2:31 PM, Antonis Kanaris <[email protected]> wrote: > >> >> Hello.I am new developer and i want a good simple and analytical >> example for get data from my website.net/ledstate.txt >> with AsyncTask....i try without asynctask and no work....this >> code...with permissions internet.... >> >> public class GetDataWeb extends Activity { >> >> @Override >> public void onCreate(Bundle savedInstanceState) { >> >> try{ >> >> super.onCreate(savedInstanceState); >> setContentView(R.layout.activity_get_data_web); >> >> TextView t = (TextView)findViewById(R.id.netResult); >> >> try{ >> >> HttpClient httpclient = new DefaultHttpClient(); >> >> HttpPost httppost = new HttpPost(" >> http://www.power7.net/LEDstate.txt"); >> >> HttpResponse response = httpclient.execute(httppost); >> >> HttpEntity entity = response.getEntity(); >> >> InputStream webs = entity.getContent(); >> >> try{ >> >> BufferedReader reader = new BufferedReader(new >> InputStreamReader(webs,"iso 8859-1"),8); >> >> t.setText(reader.readLine()); >> >> webs.close(); >> >> }catch(Exception e){ >> Log.e("log_tag","Error converting result"+e.toString()); >> >> } >> >> }catch(Exception e){ >> Log.e("log_tag","Error in http connection"+e.toString()); >> } >> >> }catch(Exception e){ >> Log.e("ERROR","ERROR IN CODE: "+e.toString()); >> e.printStackTrace(); >> } >> >> Thanks. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

