如何从存储中获取选定的文件路径?

问题描述

我的活动结果是

@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
    super.onActivityResult(requestCode,resultCode,data);

    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {

        try {
            if (data == null) {
                try {
                    String pathSource = DataUtil.getRealPathFromURI(context,lastCaptureRequestUri);
                    DataUtil.scaleDownImage(pathSource,lastCaptureRequestUri.getPath());
                    photoUriList = lastCaptureRequestUri;

                    sendbroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,lastCaptureRequestUri));
                    refreshLayoutimage();
                } catch (Exception e) {
                    e.printstacktrace();
                    exceptionAnalytics(e);
                }

            } else {

                Uri selectedImageUri = data.getData();
                // image picked Now shrink image to lastCaptureRequestUri
                try {
                    String pathSource = DataUtil.getRealPathFromURI(context,selectedImageUri);
                    DataUtil.scaleDownImage(pathSource,lastCaptureRequestUri.getPath());

                    photoUriList = lastCaptureRequestUri;

                    sendbroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,lastCaptureRequestUri));
                    refreshLayoutimage();
                } catch (FileNotFoundException e) {
                    Toast.makeText(context,getString(R.string.selected_file_not_found),Toast.LENGTH_SHORT).show();
                    e.printstacktrace();
                    exceptionAnalytics(e);
                } catch (Exception e) {
                    e.printstacktrace();
                    exceptionAnalytics(e);
                }
            }
        } catch (Exception e) {
            e.printstacktrace();
            exceptionAnalytics(e);
        }
    } else if (requestCode == REQUEST_PDF_CAPTURE && resultCode == RESULT_OK) {

        Log.i("photoUriList__",photoUriList + "--");

        if (data != null && data.getData() != null) {
            photoUriList = data.getData();
            imgvTestReport.setimageResource(R.drawable.ic_picture_as_pdf_black_36dp);
            reportimage = new File(photoUriList.getPath());
        }
    }
}

我正在从roo_path获取路径

/ root_path / storage / emulated / 0 / WhatsApp / Media / WhatsApp Documents / abc.pdf

但是我要从存储中进行存储,如下所述
存储/模拟/ 0 / WhatsApp / Media / WhatsApp文档/abc.pdf

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)