官方文档中提到使用Video capture intent进行录像,可以使用intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri)指定录像文件保存路径。
但是实际使用中如果指定路径,不能获取video,非常奇怪(使用2.3.3)。
国外开发者也有类似问题,并提出了2个解决方案:
上述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 super .onActivityResult(requestCode, if
//将存储在默认目录下的文件拷贝到指定文件夹下,删除默认文件 String null ; try
if
Uri ContentResolver this .getContentResolver(); Cursor null , null , null , null ); cursor.moveToFirst(); str videofileName cursor.close(); } File new
File new
moveFileTo(srcfile, super .onActivityResult(requestCode, } catch
} } }<div><h3> </h3><pre "brush:js;java;auto-link:false;" >public boolean if
return
; delFile(srcFile); return
; }</pre><pre "brush:js;java;auto-link:false;" >public if
return
; // FileInputStream new
FileOutputStream new
int byte[] new
while
fos.write(buf, } fos.flush(); fos.close(); fis.close(); return
; } public if
return
; return
delete (); }</pre></div> |