从Android浏览器获取文件路径

时间:2019-05-26 07:35:54

标签: android

我正在尝试从默认浏览器获取文件路径。但是我走错了路。

 Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
                fileIntent.setType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                try {
                    startActivityForResult(fileIntent, PICKFILE_RESULT_CODE);
                } catch (ActivityNotFoundException e) {
                    Log.e("tag", "No activity can handle picking a file. Showing alternatives.");
                }

OnResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data == null)
            return;
        switch (requestCode) {
            case PICKFILE_RESULT_CODE:
                if (resultCode == RESULT_OK) {

                    String filePath = data.getData().getPath();
                    Log.d("DTAG","Path: "+filePath);
                    progressBar.setVisibility(View.VISIBLE);

                }
        }
    }

但是我得到的是“ / document / 74”,它是错误的路径和文件名。

0 个答案:

没有答案