2

たとえば、Adobe で PDF を読むのが困難です。購入する前に携帯電話にインストールされていたように見える Document Viewer があります (デフォルトの Android アプリだと思いました)。これで、私のコードは正常に動作します。しかし、おそらく Document Viewer を持っていない人がクラッシュするのを見たことがあります。

だから私はアドビリーダーで自分のコードをテストしましたが、クラッシュしました!

誰かが私のコードの何が問題なのかを説明してくれませんか (および/または) ユーザーにダウンロードさせるための 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;

}

ありがとう !

ルノー

4

1 に答える 1

1

問題が見つかりました: パラメータの名前は .pdf で終わる必要があります

そうでない場合、pdf は adobe リーダーで読み取ることができません。私が試した他のすべての pdf リーダーで動作します。

みんなありがとう!

于 2012-06-11T11:54:40.820 に答える