1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
private static final String BASE_URL = "/local/home/MyHome/images/image_new.png";
private static final String BASE_URL1 = "https://3.bp.blogspot.com/-W__wiaHUjwI/Vt3Grd8df0I/AAAAAAAAA78/7xqUNj8ujtY/s1600/image02.png";
private volatile MainActivity screen;
private HttpClient client;
public DownloadImage(MainActivity s) {
this.screen = s;
}
@Override
protected Bitmap doInBackground(String... params) {
Bitmap image = null;
try{
String url = BASE_URL1;
HttpGet request = new HttpGet(url);
HttpResponse response = this.client.execute(request);
HttpEntity entity = response.getEntity();
byte[] bytes = EntityUtils.toByteArray(entity);
image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}catch (Exception e) {
android.util.Log.e("RPC", "exception leve", e);
}
return image;
}
@Override
protected void onPostExecute(Bitmap result){
this.screen.populate(result);
}
} |
Partager