2015-03-19 126 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