用以上代码碰到的问题:
- 在MIUI下无法取到照片数据,跟踪发现data.getExtras()为空,之后使用BitmapFactory.decodeFile()方法解决;
- 手机上测试没有保存图片,跟踪发现data为null,继续Google,找到以下代码
1 | Intent intent =newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); |
2 | Uri uri = Uri.fromFile(newFile(imagePath)); |
3 | intent.putExtra(MediaStore.EXTRA_OUTPUT,uri); |
4 | startActivityForResult(intent,RESULT_CAPTURE_IMAGE); |
将按钮onClick方法中采用以上代码,调用系统拍照并确定之后,无法返回程序Activity。继续Google,终于找到解决办法,代码如下(在if(resultCode == RESULT_OK)里面)
02 | File file =newFile(imagePath); |
03 | bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); |
05 | Toast.makeText(this,R.string.image_save_error,Toast.LENGTH_LONG).show(); |
08 | BufferOutputStream bos =newBufferOutputStream(newFileOutputStream(file)); |
09 | bitmap.compress(Bitmap.CompressFormat.JPEG,80,bos); |
12 | }catch(FileNotFoundException e) { |
14 | }catch(IOException e) { |
17 | super.onActivityResult(requestCode,resultCode,data); |
阅读全文……
- [Android每日精彩]我不使用Android(安卓)DataBinding的四个原因
- Android(安卓)Studio下Intent隐式启动,发短信,拨号,打电话,访问网页
- Android(安卓)studio下解决NoActionbar的问题:
- Android(安卓)Studio开发工具的使用
- Android后台开启服务默默拍照
- android电话窃听器(示例代码)
- android 简单的相册查看器
- android有用代码片段(一)
- Android实现快递物流时间轴效果
随机推荐
-
谷歌Android操作系统有望主导移动市场
-
简单解释Android中的任务、进程和线程
-
android中使用AES加解密
-
Android+SpringMVC通信
-
Android(安卓)studio璁剧疆宸ヤ綔绌洪棿/
-
Android主题定制及修改
-
[android]笔记4-线性布局
-
熟悉Android打包编译的流程
-
Android布局文件中控件的高度与宽度属性
-
Android 将 android view 的位置设为右下