Android-打开相册选择单张图片
2017-05-05 15:37
429 查看
btn8.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { /*在Activity Action里面有一个“ACTION_GET_CONTENT”字符串常量, // 该常量让用户选择特定类型的数据,并返回该数据的URI.我们利用该常量, //然后设置类型为“image/*”,就可获得Android手机内的所有image。*/ Intent intent = new Intent(); /* 开启Pictures画面Type设定为image */ intent.setType("image/*"); /* 使用Intent.ACTION_GET_CONTENT这个Action */ intent.setAction(Intent.ACTION_GET_CONTENT); /* 取得相片后返回本画面 */ startActivityForResult(intent, 1); //Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); // startActivityForResult(intent, RESULT); } }); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri uri = data.getData(); Log.e("uri", uri.toString()); ContentResolver cr = this.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); /* 将Bitmap设定到ImageView */ iv8.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(), e); } } super.onActivityResult(requestCode, resultCode, data); }
相关文章推荐
- Android 打开相册选择单张图片实现代码
- Android 打开相册,选择一张图片并返回
- android 通过Intent打开相册并获取选择的图片
- android进入系统相册选择图片
- 【Android】本地图片选择(打开媒体库,选择图片)
- android 仿微信选择相册中的图片跟图片异步加载
- IOS研究院之打开照相机与本地相册选择图片
- IOS学习:打开照相机与本地相册选择图片
- 【Android】本地图片选择(打开媒体库,选择图片)
- IOS研究院之打开照相机与本地相册选择图片(六)
- android 拍照+从手机相册选择返回图片到imagview
- IOS研究院之打开照相机与本地相册选择图片(六)
- Android大图片裁剪之手机拍照和从相册中选择注意点
- Android 调用相机、打开相册、裁剪图片
- 我的Android心得(6)--从相册中选择图片显示出来
- Android 打开照相机、获取相册图片、获取图片并裁减
- [Android] 调用相机、打开相册、裁剪图片
- 【Android】本地图片选择(打开媒体库,选择图片)
- IOS研究之打开照相机与本地相册选择图片
- Android拍照或者从手机相册里选择图片