layout文件<?xml version="1.0" encoding="utf-8"?>

class

public class showpage extends AppCompatActivity {    private String picture_String;    private ImageView Image_license;    private Bitmap img;    private ProgressDialog progressDialog;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_showpage);        Image_license = (ImageView) findViewById(R.id.Image_license);        Intent intent = new Intent();        Bundle bundle = intent.getExtras();        picture_String = bundle.getString("license");        new DownloadImage().execute();    }    private Bitmap bitmap;    class DownloadImage extends AsyncTask {            @Override        protected Object doInBackground(String... string) {            try {                String PATH = "网络上照片的地址";                URL url = new URL(picture_String);                // 打开一个连接                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();                httpURLConnection.setConnectTimeout(5000);                httpURLConnection.setRequestMethod("GET");                if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {                    // 得到服务器返回过来的流对象                    InputStream inputStream = httpURLConnection.getInputStream();                    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);                    return bitmap;                }            } catch (Exception e) {                e.printStackTrace();            }            return null;        }        @Override        protected void onProgressUpdate(Void... values) {            super.onProgressUpdate(values);        }        @Override        protected void onPostExecute(Object object) {            super.onPostExecute(object);            if (object != null) {                bitmap = (Bitmap) object;                new Handler().postDelayed(new Runnable() {                    @Override                    public void run() {                        Image_license.setImageBitmap(bitmap);                    }                }, 2000);            } else {                //失败                Toast.makeText(showpage.this, "下载失败", Toast.LENGTH_LONG).show();            }        }    }}

 

更多相关文章

  1. 类和 Json对象
  2. android 指纹验证api
  3. android发送json并解析返回json
  4. android Dialog中SeekBar的使用方法
  5. Android中Parcelable接口用法
  6. Android(安卓)DOC文档分析——Dialog
  7. android 自定义TextView中Html超链接点击事件详解
  8. 初识android
  9. 【Android(安卓)内存优化】Bitmap 内存缓存 ( Bitmap 内存复用 |

随机推荐

  1. Android发送邮件到指定邮箱(可带附件)
  2. Android使用Intent传值注意(传递Bean对象)
  3. Android自定义炫酷进度条(闪电能量条)
  4. Android 性能优化之内存优化
  5. Android 布局管理器 之 RelativeLayout&F
  6. Android uiautomator实例使用
  7. Android设置Activity全屏和无标题
  8. Android Material design 之 BottomNavig
  9. Android中MenuInflater的使用(布局文件定
  10. Android STL PORT