2012-07-11 131 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"; 
     }   
    }