public void takePic(){
String forderPath = getExternalFilesDir("") + "/pic";
File file = new File(forderPath);
if (!file.exists()){
file.mkdirs();
}
String randomNum = DateTools.getCurrentData_yyyyMMddHHmmss();
//创建File对象,用于存储拍照后的照片
File outputImage = new File(forderPath,randomNum + "_output_image.jpg");
currentImagPath = outputImage.getAbsolutePath(); try {
if (outputImage.exists()){
outputImage.delete();
}
outputImage.createNewFile();
}catch (IOException e){
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= 24){
imageUri = FileProvider.getUriForFile(context,"xxxxxx.packagename",outputImage);
}else {
imageUri = Uri.fromFile(outputImage);
}
//启动相机程序
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri); startActivityForResult(intent,TAKE_PHOTO);
}

以上是拍照程序

下面是处理

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode){
case TAKE_PHOTO:
if (resultCode == RESULT_OK){
// String mimgUri = imageUri.toString();
// String path = imageUri.getPath();
String path = getProviderUriPath(imageUri);
Uri uri = Uri.parse(path);
mUploadMessage.onReceiveValue(uri);
}
break;
}
}

其中getProviderUriPath工具类可以查看我上一篇文章

最新文章

  1. [.net 面向对象编程基础] (16) 接口
  2. 【BZOJ】1132: [POI2008]Tro
  3. 段落的展开收起(substring的应用)
  4. 查看oracle当前session
  5. 调试EF源代码环境配置
  6. Android之Http网络编程(三)
  7. JQuery(一) 入门
  8. 关于打开ILDASM的方法
  9. map函数(转)
  10. org.tigris.subversion.javahl.ClientException: Attempted to lock an already-locked dir svn: Working c
  11. DWR整合之Servlet
  12. Kubernetes使用cephfs作为后端存储
  13. SQL Server学习之路(七):Python3操作SQL Server数据库
  14. Android4.0新控件
  15. 大数据量情况下高效比较两个list
  16. Hibernate 缓存机制全面讲解
  17. java设计模式之动态代理的概述和实现
  18. [转][MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据
  19. [THUSC2017]巧克力[斯坦纳树、随机化]
  20. SQLServer2008只能编辑前面200行数据

热门文章

  1. pdf.js打开后的pdf文件
  2. TCP怎样保证可靠传输
  3. ARC157E XXYX Binary Tree 题解
  4. Neighborhood Attention Transformer概述
  5. 最全面 think php 实现微信公众号回复编号进行投票,自定义菜单功能
  6. 解决报错Could not satisfy explicit device specification '' because the node was colocated with a group of nodes that required incompatible device '/device:GPU:0'
  7. linux系统过滤文件,并且通过时间对过滤的文件排序
  8. vim自动输入P的问题
  9. java报错 SLF4J:Failed to load class "org.slf4j.impl.StaticLoggerBinder"
  10. 使用yum快速安装mysql-5.7(用于测试)