1.点击事件跳转
private void selectImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Browser Image..."),REQUEST_GET_IMAGE);
}
2.获取返回的图片并设置到ImageView中
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ( resultCode == RESULT_OK && data != null){
Uri uri = data.getData();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
try{
InputStream inputStream = getContentResolver().openInputStream(uri);
BitmapFactory.decodeStream(inputStream,null,options);
inputStream