2012-06-11 46 views
2

我有困难阅读我的pdf在Adobe上的例子。我有文档查看器,似乎已经安装在我的手机上之前,我买了它(我认为这是一个默认的Android应用程序)。有了它,我的代码工作正常。 但我已经看到崩溃,与没有文档查看器的人合作。从嵌入式文件与Android应用程序读取pdf的每个第三个应用程序

所以我测试了我的代码与Adobe Reader,它崩溃了!

有人能解释我什么是我的代码有问题(和/或)给我的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; 

} 

谢谢!

雷诺

+0

我找到了“文档查看器”包:com.tf.thinkdroid.sg –

+0

发布您的崩溃日志! –

+0

对不起,没有崩溃,只是土坯读者说我的pdf无效,wearas它与文档查看器(应用程序不再可用在播放存储:) :() –

回答

1

我发现了问题: 在parametre名称具有通过.PDF

结束,如果它不,PDF格式不能由Adobe阅读器读取,whearas它的工作原理我试过的所有其他pdf阅读器!

谢谢大家!

相关问题