龙岩易富通网络科技有限公司

龙岩小程序开发,龙岩分销系统

android拍照获得图片URI为空的处理方法

2015.09.10 | 916阅读 | 0条评论 | 未命名

在拍照的时候,获得图片URI为空, 发起intent请求: [php] private void getBitmapFromTakePictrue() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); this.startActivityForResult(intent, 3); } [/php] 处理结果: [php] @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Bundle bundle = data.getExtras(); Bitmap bitmap = (Bitmap) bundle.get("data");// 获取相机返回的数据,并转换为Bitmap图片格式 if (data.getData() != null) { uri ImageData = data.getData(); } else { uri ImageData = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, null,null)); } } [/php] 如果获取到的 [php]data.getData() 为空的时候,则需要使用[/php] [php]Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, null,null));方法将bitmap获取它的uri,这样就可以解决当部分手机拍照获取图片uri为空的情况。[/php]

赞 (

发表评论