最近我正在开发一个android应用程序内置的phonegap,我是一个很新的移动开发,这我smy第一个应用程序但是,当我尝试将一些文件(pdf,doc,jpg)下载到本地存储并打开它时,我陷入困境,通过谷歌搜索后,我试图遵循这个解决方案.
我按照示例中的确切代码,下面是我如何调用插件:
window.plugins.downloader.downloadFile(url,'/sdcard/download/', 'test.pdf', true, downloadOkCallbak, downloadErCallbak);
window.plugins.pdfViewer.showPdf('/sdcard/download/test.pdf');
Run Code Online (Sandbox Code Playgroud)
url是我的远程文件,当我执行它时,我收到错误:"TypeError:window.plugins is undefined".任何帮助表示赞赏.
[更新]我的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";
}
}
Run Code Online (Sandbox Code Playgroud)
[更新2]我在Web控制台中遇到以下错误:Uncaught ReferrenceError:LocalFileSystem未在...中定义
可能是什么问题?
我在我的网络应用程序中使用jquery插件bootstrapToggle,在这里遇到一个问题,我的代码如下
<input id="toggle-event" type="checkbox" data-toggle="toggle">
<script>
$(function() {
$('#toggle-event').change(function() {
if (some condition) {
$('#console-event').bootstrapToggle('toggle');
}
})
})
</script>
Run Code Online (Sandbox Code Playgroud)
基本上我想做的是,当有人单击复选框时,我会做一些检查,如果条件失败,我将切换复选框以将其设置回来。
这里的问题是,检查失败后,复选框切换回来,再次触发change事件,然后陷入死循环,有没有办法防止条件失败时触发change事件?谢谢。