read pdfs on android from embeded files with every third app

I have difficulties to read my pdfs on adobe for example. I have Document Viewer which seems to have been installed on my phone before I bought it (I thought it was a default android app). With it, my code works fine. But I've seen crash, propably with people who doesn't have Document Viewer.

so I tested my code with the adobe reader, and it crashes !

could someone explain me what is wrong with my code (and/or) give me the Gplay link to make my users download it.

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;

}

Thanks !

Renaud

Answers


I found the issue : The name in parametre has to end by .pdf

if it doesn't, the pdf can't be read by adobe reader, whearas it works with all the other pdf reader that i've tried !

Thanks everybody !


Need Your Help

Add space for each word in array

javascript jquery string

I have number N (For example 9) and array with some words

Akka or Reactor

java spring akka reactor project-reactor

I am in the process of starting a new project (java-based). I need to build it as a modular, distributed and resilient architecture.