1

我在 android phonegap 中非常新。我想从我的 SD 卡打开 pdf 文件。我正在使用这个链接

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

在这里,存储在 sdcard 中的 pdf 文件,而我尝试打开该文件意味着它在我的 logcat 中显示以下错误消息

PdfViewer:加载网址时出错

/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 }

任何人都可以帮助我吗?

4

1 回答 1

0

现在上面的问题解决了,这里是我的代码:

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";
        }        
    }
于 2012-07-30T09:03:58.367 回答