Android拍照程序适配
2024-09-08 18:29:37
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工具类可以查看我上一篇文章
最新文章
- [.net 面向对象编程基础] (16) 接口
- 【BZOJ】1132: [POI2008]Tro
- 段落的展开收起(substring的应用)
- 查看oracle当前session
- 调试EF源代码环境配置
- Android之Http网络编程(三)
- JQuery(一) 入门
- 关于打开ILDASM的方法
- map函数(转)
- org.tigris.subversion.javahl.ClientException: Attempted to lock an already-locked dir svn: Working c
- DWR整合之Servlet
- Kubernetes使用cephfs作为后端存储
- SQL Server学习之路(七):Python3操作SQL Server数据库
- Android4.0新控件
- 大数据量情况下高效比较两个list
- Hibernate 缓存机制全面讲解
- java设计模式之动态代理的概述和实现
- [转][MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据
- [THUSC2017]巧克力[斯坦纳树、随机化]
- SQLServer2008只能编辑前面200行数据
热门文章
- pdf.js打开后的pdf文件
- TCP怎样保证可靠传输
- ARC157E XXYX Binary Tree 题解
- Neighborhood Attention Transformer概述
- 最全面 think php 实现微信公众号回复编号进行投票,自定义菜单功能
- 解决报错Could not satisfy explicit device specification '' because the node was colocated with a group of nodes that required incompatible device '/device:GPU:0'
- linux系统过滤文件,并且通过时间对过滤的文件排序
- vim自动输入P的问题
- java报错 SLF4J:Failed to load class ";org.slf4j.impl.StaticLoggerBinder";
- 使用yum快速安装mysql-5.7(用于测试)