2015-03-19 64 views
0

Iam使用adobe pdf阅读器使用一种方法打开存储在我的SD卡中的PDF文件在Android应用程序中的方法。我正在使用的代码如下所示。使用Abobe pdf阅读器不能显示pdf在Android中

File file=new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+"/Report.pdf"); 
      Uri path=Uri.fromFile(file); 
      //openFile(file, "application/pdf"); 
      viewPdf(path); 


private void viewPdf(Uri file){ 
    Intent intent; 
    intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(file, "application/pdf"); 
    try{ 
    startActivity(intent); 
    }catch(ActivityNotFoundException e){ 
    AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
    builder.setTitle("No Application Found"); 
    builder.setMessage("Download from Android Market?"); 
    builder.setPositiveButton("Yes, Please", new DialogInterface.OnClickListener() { 

    @Override 
    public void onClick(DialogInterface dialog, int which) { 
    // TODO Auto-generated method stub 

    Intent marketIntent = new Intent(Intent.ACTION_VIEW); 
    marketIntent.setData(Uri.parse("market://details?id=com.adobe.reader")); 
    startActivity(marketIntent); 

    } 
    }); 
    builder.setNegativeButton("No, Thanks", null); 
    builder.create().show(); 

    } 
} 

并且在烤面包中显示以下例外:无法显示pdf(xyz.pdf无法打开)。

请帮我一把。

+0

有任何PDF阅读器应用程序在安装到您的设备或模拟器上? – 2015-03-19 05:24:24

+0

尝试在意图中设置包:intent.setPackage(“com.adobe.reader”); – 2015-03-19 05:25:37

+0

@HareshChhelana是有两个安装的一个是土坯其他是极地办公室5 ...是的,我用com.adobe.reader仍然是异常。如果你有一个工作的例子,请发布它。 – user3469177 2015-03-19 05:33:49

回答

0

尝试使用包名称来识别特定的开放PDF阅读器应用程序:

Intent intent; 
intent = new Intent(Intent.ACTION_VIEW); 
intent.setPackage("com.adobe.reader"); 
intent.setDataAndType(file, "application/pdf"); 
+0

还是没有帮助同样的问题“无法打开Report.pdf”反正pdf的大小是323 kb没有关系吗? – user3469177 2015-03-19 05:50:04

+0

你有没有尝试打开一些其他的PDF文件? – 2015-03-19 06:18:01

+0

是的,我做了没有帮助,无论是... – user3469177 2015-03-19 08:55:02