Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package com.display.picture;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.File;
  5. import java.io.InputStream;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8.  
  9. import android.app.Activity;
  10. import android.os.Bundle;
  11. import android.graphics.Bitmap;
  12. import android.graphics.BitmapFactory;
  13. import android.widget.Button;
  14. import android.widget.EditText;
  15. import android.widget.ImageView;
  16. import android.widget.Toast;
  17.  
  18. public class DisplayPictureActivity extends Activity {
  19.  
  20. private EditText et;
  21. private Button btn;
  22. private ImageView iv;
  23.  
  24. @Override
  25. public void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.main);
  28.  
  29. et = (EditText) findViewById(R.id.et1);
  30. btn = (Button) findViewById(R.id.btn1);
  31. iv = (ImageView) findViewById(R.id.iv1);
  32.  
  33. try
  34. {
  35. URL url = new URL("");
  36. URLConnection connection = url.openConnection();
  37. connection.connect();
  38. InputStream is = connection.getInputStream();
  39. BufferedInputStream bis = new BufferedInputStream(is);
  40. Bitmap bitmap = BitmapFactory.decodeStream(bis);
  41. ImageView myImage = (ImageView) findViewById(R.id.iv1);
  42. myImage.setImageBitmap(bitmap);
  43. bis.close();
  44. is.close();
  45. }
  46. catch (Exception e) {
  47. Toast toast = Toast.makeText(getBaseContext(), "Failed to Download Image",
  48. Toast.LENGTH_LONG);
  49. toast.show();
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement