Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Programming 4

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Android Programming 4

This slides explain simple usage of network, webview and toast

Giovanni De Francesco

February 01, 2013

Transcript

11 slides
  1. Using Internet ›  Add internet permission on our app, modifying

    manifest file (after sdk declaration). ›  <uses-permission android:name=” android.permission.INTERNET"/> Android Programming
  2. Let’s Download! HttpClient client = new DefaultHttpClient(); HttpGet request =

    new HttpGet(”url”); HttpResponse response = client.execute(request); Android Programming
  3. Where is my download? InputStream in = response.getEntity().getContent(); BufferedReader reader

    = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = reader.readLine(); str.append(line); //yours download should be here. String out = str.toString(); Android Programming
  4. AsyncTask public class MyTask extends AsyncTask<T, T, T> { @Override

    protected Boolean doInBackground(T… params){ // must be implemented } } Android Programming
  5. Other useful method @Override protected void onPreExecute() { //Called before

    doInBackground() } @Override protected void onProgressUpdate(T... values) { } @Override protected void onCancelled() { } @Override protected void onPostExecute(T result) { //Called after doInBackground() } Android Programming
  6. What should we do today? First Step ›  When the

    user click on the “go” button the app will show the web page for the url entered. ›  When the user click the “save” button , the page displayed will be saved on internal storage with her title as name. Android Programming
  7. What should we do today? Second Step ›  When the

    user click on a page title, the page saved will be displayed. Android Programming

More Decks by Giovanni De Francesco

Other Decks in Programming