且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将文件路径转换为以URI在android系统

更新时间:2023-02-25 15:13:26

  Uri.fromFile(新文件(/ SD卡/ sample.jpg)

Hi i am new android i am trying to upload the video to *** 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")