Android调用系统Camera录像时不能指定保存路径的问题
来源:互联网 发布:遗传算法的书pdf版本 编辑:程序博客网 时间:2024/06/05 16:53
官方文档中提到使用Video capture intent进行录像,可以使用intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri)指定录像文件保存路径。
但是实际使用中如果指定路径,不能获取video,非常奇怪(使用2.3.3)。
国外开发者也有类似问题,并提出了2个解决方案:
http://stackoverflow.com/questions/13035638/intent-for-video-recording-gives-error
http://stackoverflow.com/questions/9003423/error-calling-mediastore-action-video-capture
上述2种做法有点绕,以下是我的解决方法,先从onActivityResult中的intent得到文件路径,然后复制到指定目录,再删除原文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super
.onActivityResult(requestCode, resultCode, data);
if
(resultCode == Activity.RESULT_OK) {
//将存储在默认目录下的文件拷贝到指定文件夹下,删除默认文件
String str =
null
;
try
{
if
(requestCode == 1) {
Uri uri = Uri.parse(data.getData().toString());
ContentResolver cr =
this
.getContentResolver();
Cursor cursor = cr.query(uri,
null
,
null
,
null
,
null
);
cursor.moveToFirst();
str = cursor.getString(1);
videofileName = cursor.getString(2);
cursor.close();
}
File destfile =
new
File(strsavedir + videofileName);
File srcfile =
new
File(str);
moveFileTo(srcfile, destfile);
super
.onActivityResult(requestCode, resultCode, data);
}
catch
(Exception e) {;
}
}
}<div><h3> </h3><pre class=
"brush:js;java;auto-link:false;"
>public boolean moveFileTo(File srcFile, File destFile) throws IOException {
boolean iscopy = copyFileTo(srcFile, destFile);
if
(!iscopy)
return
false
;
delFile(srcFile);
return
true
;
}</pre><pre class=
"brush:js;java;auto-link:false;"
>public boolean copyFileTo(File srcFile, File destFile) throws IOException {
if
(srcFile.isDirectory() || destFile.isDirectory())
return
false
;
// 判断是否是文件
FileInputStream fis =
new
FileInputStream(srcFile);
FileOutputStream fos =
new
FileOutputStream(destFile);
int readLen = 0;
byte[] buf =
new
byte[1024];
while
((readLen = fis.read(buf)) != -1) {
fos.write(buf, 0, readLen);
}
fos.flush();
fos.close();
fis.close();
return
true
;
}
public boolean delFile(File file) {
if
(file.isDirectory())
return
false
;
return
file.
delete
();
}</pre></div>
- Android调用系统Camera录像时不能指定保存路径的问题
- Android调用系统Camera录像时不能指定保存路径的问题
- Android调用系统Camera录像时不能指定保存路径的问题
- 调用系统UIImagePickerController录像并保存到指定的文件夹,解决保存后播放视频角度偏移90度问题
- Android中调用系统摄像并且保存到指定位置的一些问题&Uri转文件路径方法
- 调用系统相机拍照片保存到指定的路径
- Android使用camera录像时保存数据到手机上
- 初识Camera,调用系统拍照录像程序
- 关于Android中调用系统拍照和剪裁,不能保存的问题
- Android问题集锦之三十九:使用Camera录像的常见问题
- Android系统Camera录像过程分析
- Android系统Camera录像过程分析
- Android系统Camera录像过程分析
- Android系统Camera录像过程分析
- Android系统Camera录像过程分析
- Android系统Camera录像过程分析
- android 调用系统图库打开指定路径的图片
- android 调用系统图库查看指定路径的图片
- 图片的放大与缩小
- 读《JavaServer Faces 核心编程(第3版)》一书的记录—— 第 4 章 标准 JSF 标签——案例 select
- Beyond Compare 文件比较工具
- android 录像和拍照功能
- bmp转jpg(使用libjpeg)
- Android调用系统Camera录像时不能指定保存路径的问题
- Struts 1.3学习总结(3)
- 各位是如何放假的?
- android悬浮窗口的实现
- Ubuntu在终端中使用su切换到root权限
- OGCer V1.1 released
- G10: longest palindrome or every palindrome
- JSP、Servlet、Struts2学习笔记(持续更新)
- 自己动手制作最新版struts2.3.8的chm格式的api帮助文档