文档路径无法在Android中打开PDF

时间:2014-09-27 15:37:09

标签: java android

我正在尝试从网址显示PDF文件,但我无法使用下面的功能打开它。它返回“文档路径无效”错误。

private void DownloadPdf(String strURL) {
        try {
            String extStorageDirectory = Environment
                    .getExternalStorageDirectory().toString();
            File folder = new File(extStorageDirectory, "pdf");
            folder.mkdir();
            File file = new File(folder, "test123.pdf");
            try {
                file.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            Downloader.DownloadFile(strURL, file);
            OpenPdf();
        } catch (Exception e) {
            // e.printStackTrace();
        }
    } catch (Exception ex) {

    }
}

private void OpenPdf() {
    File file = new File(Environment.getExternalStorageDirectory()
            + "/pdf/Read.pdf");
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(file);
    intent.setDataAndType(uri, "application/pdf");
    startActivity(intent);
}

0 个答案:

没有答案