每三个应用程序从嵌入的文件中读取android上的PDF

每三个应用程序从嵌入的文件中读取android上的PDF,android,pdf,Android,Pdf,例如,我很难在adobe上阅读PDF。我有一个Document Viewer,它似乎在我买手机之前就已经安装在我的手机上了(我还以为它是一个默认的android应用程序)。有了它,我的代码运行良好。 但我见过崩溃,很可能是因为没有文档查看器的人 所以我用AdobeReader测试了我的代码,结果它崩溃了 有人能解释一下我的代码有什么问题吗(和/或)给我Gplay链接让我的用户下载它 public Intent readPdf(String name, int res) { final S

例如,我很难在adobe上阅读PDF。我有一个Document Viewer,它似乎在我买手机之前就已经安装在我的手机上了(我还以为它是一个默认的android应用程序)。有了它,我的代码运行良好。 但我见过崩溃,很可能是因为没有文档查看器的人

所以我用AdobeReader测试了我的代码,结果它崩溃了

有人能解释一下我的代码有什么问题吗(和/或)给我Gplay链接让我的用户下载它

public Intent readPdf(String name, int res) {
    final String extStorageDirectory = Environment
            .getExternalStorageDirectory().toString();
    final String festivalDirectory_path = extStorageDirectory
            + Constants.PDF_STORAGE_PATH;
    File pdfOutputFile = new File(festivalDirectory_path, "/");
    if (pdfOutputFile.exists() == false) {
        pdfOutputFile.mkdirs();
    }
    File pdfFile = new File(pdfOutputFile, name);
    // AssetManager assetManager = getAssets();
    InputStream in = null;
    try {
        // InputStream in = assetManager
        // .open("cartecannesplus01pdf.pdf");
        in = getResources().openRawResource(res);

        OutputStream out = new FileOutputStream(pdfFile);
        byte[] buffer = new byte[1024];
        int bufferLength = 0;
        while ((bufferLength = in.read(buffer)) > 0) {
            out.write(buffer, 0, bufferLength);
        }
        out.flush();
        out.close();
    } catch (Exception e) {
        Log.e("tag", e.getMessage());
    }
    Uri path = Uri.fromFile(pdfFile);


    Intent intent = null;
    if (Utils.appInstalledOrNot(me, "com.adobe.reader")) {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } else {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=com.adobe.reader"));
    }

    return intent;

}
谢谢

雷诺

我发现了问题: Parameter中的名称必须以.pdf结尾

如果没有,adobe reader将无法读取pdf,因为它可以与我尝试过的所有其他pdf阅读器一起工作


谢谢大家

我发现“document viewer”软件包:com.tf.thinkdroid.sg很抱歉没有崩溃,只是adobe reader说我的pdf无效,wearas它与document viewer配合使用效果很好(应用程序在play store上不再可用:()我尝试了此代码..在我这方面效果很好。