我有下面的代码,让用户从那里设备选择一个pdf文件,但是目前看来传递的URI路径不是绝对的 .

public void openPDF(int type){

        Intent intent = new Intent();
        intent.setType("application/pdf");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select PDF "), type);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK) {

            if (requestCode == SELECT_PDF_CV)
            {
                System.out.println("SELECT_PDF");
                Uri selectedImageUri = data.getData();
                cvselectedPath = selectedImageUri.getPath();
                System.out.println("SELECT_AUDIO Path : " + cvselectedPath);
            }

        }
    }

例如,当我从模拟器中的下载管理器中选择文件时 cvselectedPath == /document/3

选择的文件实际上是/sdcard/downloads/sample.pdf

如何获取文件的实际绝对路径,以便我可以创建一个准备好进行处理的 File 对象 .

评论中给出的代码不起作用,因为我得到了一个内容:uri with it so

Uri uri = data.getData();
                String type = data.getType();
                Log.i(TAG,"Pick completed: "+ uri + " "+type);
                if (uri != null)
                {
                    String path = uri.toString();
                    if (path.toLowerCase().startsWith("file://"))
                    {
                        // Selected file/directory path is below
                        path = (new File(URI.create(path))).getAbsolutePath();
                    }
                    Log.i(TAG,"path completed: " + path);

                }

选择完成:内容:// media / external / file / 2007 application / pdf path completed:content:// media / external / file / 2007