最近我正在开发一个在phonegap中构建的android应用程序,我对移动开发很陌生,这是我的第一个应用程序但是,当我尝试将一些文档(pdf,doc,jpg)下载到本地存储并打开它时,我被卡住了,通过谷歌搜索后,我试图遵循这个解决方案。
我遵循示例中的确切代码,以下是我调用插件的方式:
window.plugins.downloader.downloadFile(url,'/sdcard/download/', 'test.pdf', true, downloadOkCallbak, downloadErCallbak);
window.plugins.pdfViewer.showPdf('/sdcard/download/test.pdf');
该 url 是我的远程文件,当我执行它时,出现错误:“TypeError:window.plugins 未定义”。任何帮助表示赞赏。
[更新]我的 showPdf 函数代码:
public String showPdf(String fileName) {
File file = new File(fileName);
if (file.exists()) {
try {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.setData(Uri.parse(fileName));
this.ctx.startActivity(intent);
return "";
} catch (android.content.ActivityNotFoundException e) {
System.out.println("PdfViewer: Error loading url "+fileName+":"+ e.toString());
return e.toString();
}
}else{
return "file not found";
}
}
[更新 2]我在 Web 控制台中收到以下错误:未捕获的引用错误:LocalFileSystem 未定义在 ...
可能是什么问题?