首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Android中将文件路径转换为Uri

在Android中将文件路径转换为Uri
EN

Stack Overflow用户
提问于 2014-12-22 20:43:14
回答 3查看 170.7K关注 0票数 110

我有一个应用程序,我可以用相机捕捉视频。我可以获得视频的文件路径,但我需要将其作为Uri。

我得到的文件路径是:

代码语言:javascript
复制
/storage/emulated/0/DCIM/Camera/20141219_133139.mp4

我需要的是这样的:

代码语言:javascript
复制
content//media/external/video/media/18576.

这是我的代码。

代码语言:javascript
复制
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();
            }
        }
    }

我需要一个来自字符串变量bedroom的Uri。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27602986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档