android相机保存文件为空,相机不保存到指定的文件位置android
我已经看到了Android和/或硬件的某些版本不尊重MediaStore.EXTRA_OUTPUT标志。我有这样的评论+解决方案在我的代码:
/*
* HTC Eris and possibly other phones DONT respect the MediaStore.EXTRA_OUTPUT flag and they only
* return the image URI in the Data. In Android instances where the MediaStore.EXTRA_OUTPUT *IS* respected
* then Data is null. So use this fact retrieve the correct bitmap reference. When we have to return it from
* Data then just copy it to the fileUri that we tried to store it in the first place via
* MediaStore.EXTRA_OUTPUT.
*/
private void gotoCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String mBoothFileName = "snap_" + (new Date()).getTime() + ".jpg";
mStateHolder.mPictureFile = new File(((BatchApp) getApplication()).getStorageDirectory(), mBoothFileName);
mStateHolder.mPictureUri = Uri.fromFile(mStateHolder.mPictureFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mStateHolder.mPictureUri);
startActivityForResult(intent, TAKE_PICTURE);
}
/*
* When the post Camera activity returns
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE) {
if (resultCode == RESULT_OK) {
/*
* HTC Eris and possibly other phones DONT respect the MediaStore.EXTRA_OUTPUT flag and they only
* return the image URI in the Data. In Android instances where the MediaStore.EXTRA_OUTPUT *IS* respected
* then Data is null. So use this fact retrieve the correct bitmap reference. When we have to return it from
* Data then just copy it to the fileUri that we tried to store it in the first place via
* MediaStore.EXTRA_OUTPUT. See how sneaky we are....
*/
if (data != null && data.getData() != null) {
Uri imageUri = data.getData();
try {
InputStream input = getContentResolver().openInputStream(imageUri);
FileOutputStream output = new FileOutputStream(mStateHolder.mPictureFile);
/*
From Apache Commons IO: copy one stream to another:
http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/IOUtils.html
*/
IOUtils.copy(input, output);
mStateHolder.mPictureUri = Uri.fromFile(mStateHolder.mPictureFile);
} catch (Exception e) {
Toast.makeText(this, "Oops - couldn't capture your picture.", Toast.LENGTH_LONG).show();
}
}
}
// you now have your image at "mStateHolder.mPictureUri"
// do whatever you need to do ...
}
}
android相机保存文件为空,相机不保存到指定的文件位置android相关推荐
- python 去掉文件后缀_python从zip中删除指定后缀文件(推荐)
一,说明 环境:python2 用到的模块 os zipfile shutil 程序功能:从zip中删除指定后缀的文件,然后再自动压缩 函数说明: DelFileInZip(path,suffix) ...
- excel怎么连接html文件夹,excel如何批量超链接到指定的文件夹,看完你就知道了...
在我们平时做excel文件时,一列的数据往往会对应有附件,但是我们只能通过手动的方式进行超链接的连接,本篇文章教你使用一个函数即可批量完成. 工具/材料 excel 操作方法 01 了解函数 在这篇实 ...
- 链接ftp,把文件或图片上传到ftp指定的文件夹中
/******************************************************************** * * * Filename : .java * Auth ...
- python中系统找不到指定文件怎么办,Python“系统找不到指定的文件”
我正在尝试编写一个OpenDyslexic字体的安装程序.我已经在https://github.com/kirbyfan64/OpenDyslexic-Installer上有一个Linux版本,但是W ...
- SpringBoot - resource资源文件的打包配置详解(指定资源文件位置)
一.问题描述 (1)默认 Spring Boot 项目结构,资源文件放置在 src/main/resources 中,测试的资源文件在 src/test/resources 中. src/main/r ...
- 创建c语言编译错误,创建C语言项目时,无法编译成*.exe文件,提示系统找不到指定的文件...
你好: 这是配置管理器,没看懂 https://skydrive.live.com/redir?resid=56EDD5214D16058E!172&authkey=!AFt6lfaQijGu ...
- 天正lisp文件路径_在AutoCAD中查找指定支持文件的文件路径
涵盖的产品和版本 AutoCAD 2005, AutoCAD 2006, AutoCAD 2007, AutoCAD 2008, AutoCAD 2009, AutoCAD 2010, AutoCAD ...
- android系统密码文件夹,安卓手机如何隐藏(加密)文件夹(软件) 安卓手机隐藏(加密)文件夹(软件)的方法...
今天给大家带来安卓手机如何隐藏(加密)文件夹(软件),安卓手机隐藏(加密)文件夹(软件)的方法,让您轻松解决问题. 在使用安卓手机的过程当中,我们往往出于各种各样的原因,对于文件夹需要做一定的保护.而 ...
- 写文件 —— 将内容按照指定格式写入配置文件(fwrite()函数-》》向指定的文件中写入若干数据块)
例如 -- 文件中的配置内容格式如下: dat.txt的文件的内容为 [root@localhost tool]# cat dat.txt aa1213bbcc1415dd 参数说明 size_t ...
最新文章
- node.js(四)小结
- Jmeter拓展插件(jmeter-plugins)
- 《EMCAScript6入门》读书笔记——24.编程风格
- ggplot2设置坐标轴范围_ggplot2画图时出现重合的点以及标签如何处理?有现成的包ggrepel
- VHDL中的分辨函数
- 在SQL Server2005中使用 .NET程序集
- mysql意外关闭xampp_错误:MySQL意外关闭xampp 3.2.4
- 项目经理感悟之风险管理
- maven项目的构建
- C语言表白代码,复杂动态爱心
- Oracle 索引详解(index)
- 这么好用的PDF密码移除器,你知道吗
- Win10能聊微信不能上网的解决方案
- cvpr论文什么级别(cvpr论文什么级别,有奖金吗)
- JavaSE-饿了么项目实战
- Android 自定义相机 切换相机 参考线(辅助线) 闪光灯 缩放 自动聚焦 Demo
- iOS两个.a文件合并成一个.a文件
- 【人工智能】谭铁牛院士:人工智能新动态
- 计算机哪个自考学校好,哪个学校的自考计算机专业本科比较好通过?
- EMP v5.3 技术白皮书
热门文章
- linux主机怎么建站,linux主机建站
- Linux中which命令作用,【每天一个Linux命令】12. Linux中which命令的用法
- Spring Cloud Alibaba 2021.0.1.0 发布:版本号再也不迷糊了
- 我去!每天都用的这个操作居然算“黑客行为”?
- 皮一皮:大家对自己的定位都挺准的...
- 程序员的“鱿鱼游戏”,你能活到第几关?
- 让隔壁同事哇塞的IDEA主题!
- 由Linux内核bug引起SSH登录缓慢问题的排查与解决
- 一文搞懂 Prometheus 的直方图
- 国内技术原创氛围为什么那么差?记EAWorld(普元)是如何靠“借鉴”产出原创文章的!