用以上代码碰到的问题:

  1. 在MIUI下无法取到照片数据,跟踪发现data.getExtras()为空,之后使用BitmapFactory.decodeFile()方法解决;
  2. 手机上测试没有保存图片,跟踪发现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)里面)

01 Bitmap bitmap =null;
02 File file =newFile(imagePath);
03 bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
04 if(bitmap ==null) {
05 Toast.makeText(this,R.string.image_save_error,Toast.LENGTH_LONG).show();
06 }
07 try{
08 BufferOutputStream bos =newBufferOutputStream(newFileOutputStream(file));
09 bitmap.compress(Bitmap.CompressFormat.JPEG,80,bos);
10 bos.flush();
11 bos.close();
12 }catch(FileNotFoundException e) {
13 e.printStackTrace();
14 }catch(IOException e) {
15 e.printStackTrace();
16 }
17 super.onActivityResult(requestCode,resultCode,data);

阅读全文……

更多相关文章

  1. [Android每日精彩]我不使用Android(安卓)DataBinding的四个原因
  2. Android(安卓)Studio下Intent隐式启动,发短信,拨号,打电话,访问网页
  3. Android(安卓)studio下解决NoActionbar的问题:
  4. Android(安卓)Studio开发工具的使用
  5. Android后台开启服务默默拍照
  6. android电话窃听器(示例代码)
  7. android 简单的相册查看器
  8. android有用代码片段(一)
  9. Android实现快递物流时间轴效果

随机推荐

  1. 谷歌Android操作系统有望主导移动市场
  2. 简单解释Android中的任务、进程和线程
  3. android中使用AES加解密
  4. Android+SpringMVC通信
  5. Android(安卓)studio璁剧疆宸ヤ綔绌洪棿/
  6. Android主题定制及修改
  7. [android]笔记4-线性布局
  8. 熟悉Android打包编译的流程
  9. Android布局文件中控件的高度与宽度属性
  10. Android 将 android view 的位置设为右下