图像下载在android中无效

时间:2016-01-20 06:48:46

标签: android image

我正在尝试从网址http://dbh_cache.s3.amazonaws.com/19445/34173cb38f07f89ddbebc2ac9128303f-33b64a2ed0f1ff4750f183b4f2a161b8.png

下载图片

URL的域似乎包含下划线,导致图像下载失败。如果我是正确的,请告诉我

1 个答案:

答案 0 :(得分:0)

public class LoadImage extends AsyncTask<String, String, Bitmap> {


        ImageView img;
        Bitmap bitmap;
        Context con;
        ProgressDialog pDialog;
    public LoadImage(Context updateProfileActivity,
                ImageView profileImageView) {
            // TODO Auto-generated constructor stub
        con   = updateProfileActivity;  
        img = profileImageView;
    }
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(con);
        pDialog.setMessage("Loading Image ....");
        pDialog.show();

    }
     protected Bitmap doInBackground(String... args) {
         try {
               bitmap = BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent());

        } catch (Exception e) {
              e.printStackTrace();
        }
        return bitmap;
     }

     protected void onPostExecute(Bitmap image) {

         if(image != null){
         img.setImageBitmap(image);
         pDialog.dismiss();

         }else{

         pDialog.dismiss();
       //  Toast.makeText(MainActivity.this, "Image Does Not exist or Network Error", Toast.LENGTH_SHORT).show();

         }
     }
 }