如何将文件路径转换为以URI在android系统 [英] how to convert the file path into to uri in android
本文介绍了如何将文件路径转换为以URI在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我是新的android我试图将视频上传到YouTube后,我捕获视频。
我可以能够得到string.I路径要转换的URI。
我收到路径是/storage/emulated/0/DCIM/Camera/20141219_133139.mp4
我需要这样的转换://内容媒体/外部/视频/媒体/ 18576
这是我的code。
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
//如果结果是捕获的图像 如果(要求code == CAMERA_CAPTURE_VIDEO_REQUEST_ code){
如果(结果code == RESULT_OK){
//视频录制成功
// preVIEW录制的视频
// selectedImageUri = data.getData();
//乌里selectedImage = data.getData();
previewVideo(); tv1.setText(将String.valueOf((fileUri.getPath())));
字符串卧室=将String.valueOf((fileUri.getPath()));
意图I =新意图();
i.putExtra(bhk1.BEDROOM2,卧室);
的setResult(RESULT_OK,I);
btnRecordVideo.setText(夺回视频); }否则如果(结果code == RESULT_CANCELED){
//用户取消记录
Toast.makeText(getApplicationContext(),
用户已取消录像,Toast.LENGTH_SHORT)
。显示();
}其他{
//未能录制视频
Toast.makeText(getApplicationContext(),
对不起!无法录制视频,Toast.LENGTH_SHORT)
。显示();
}
}
}
我想要得到的刺痛卧室URI值;
在此先感谢
解决方案
Uri.fromFile(新文件(/ SD卡/ sample.jpg)
Hi i am new android i am trying to upload the video to youtube after i capture the video. I can able to get the path in string.I want to convert into Uri.
I am getting the path is /storage/emulated/0/DCIM/Camera/20141219_133139.mp4
I need to convert like this:content//media/external/video/media/18576.
This is my code.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_VIDEO_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// video successfully recorded
// preview the recorded video
// selectedImageUri = data.getData();
// Uri selectedImage = data.getData();
previewVideo();
tv1.setText(String.valueOf((fileUri.getPath())));
String bedroom=String.valueOf((fileUri.getPath()));
Intent i = new Intent();
i.putExtra(bhk1.BEDROOM2, bedroom);
setResult(RESULT_OK,i);
btnRecordVideo.setText("ReTake Video");
} else if (resultCode == RESULT_CANCELED) {
// user cancelled recording
Toast.makeText(getApplicationContext(),
"User cancelled video recording", Toast.LENGTH_SHORT)
.show();
} else {
// failed to record video
Toast.makeText(getApplicationContext(),
"Sorry! Failed to record video", Toast.LENGTH_SHORT)
.show();
}
}
}
I want get the uri value for the sting bedroom;
Thanks in advance
解决方案
Uri.fromFile(new File("/sdcard/sample.jpg")
这篇关于如何将文件路径转换为以URI在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文