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

时间:2020-09-22 10:31:54

标签: android android-storage

我的活动结果是

@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

0 个答案:

没有答案