2012-07-11 101 views
1

我在android phonegap中非常新。我想從我的SD卡打開pdf文件。 我使用這個鏈接Android Phonegap:打開pdf文件

http://www.giovesoft.com/2011/08/download-and-open-pdf-with-phonegap.html

這裏,存儲在SD卡該PDF文件,而我嘗試打開該文件在我的logcat

PDF查看器的意思是它顯示了以下錯誤信息:錯誤加載網址

/sdcard/Downloads/:android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] 
dat=file:///sdcard/Downloads typ=application/pdf flg=0x4000000 } 

任何一個能幫助我嗎?

+0

具有u currectly檢查烏爾SD卡路徑? – Aamirkhan 2012-07-11 13:12:59

+0

確保你有一個pdf查看器應用程序安裝,我有一個在這裏工作的應用程序 - https://github.com/dhavaln/cordova-examples/tree/master/android-cordova-download/ – dhaval 2012-07-11 18:05:01

+0

是的,我檢查了我的SD卡路徑我的pdf文件可用 – user 2012-07-12 03:32:20

回答

0

現在上面proble是解決了,在這裏我的代碼:

public String showPdf(String fileName) {  
     File file = new File(fileName); 
     Log.d("PdfViewer", "list: " + file.exists()); 
     if (file.exists()) { 
      try {    
       Intent intent = new Intent();     
       intent.setDataAndType(Uri.fromFile(file), "application/pdf"); 
       this.ctx.startActivity(intent); 

       Log.d("PdfViewerr", "read: " + fileName); 
       return ""; 
      } catch (android.content.ActivityNotFoundException e) { 
       System.out.println("PdfViewer: Error loding url "+fileName+":"+ e.toString()); 
       Log.d("PdfViewer", "error: " + fileName); 
       return e.toString(); 
      }  

     }else{ 
      Log.d("PdfViewer", "notfound: " + fileName); 
      return "file not found"; 
     }   
    }