最近、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 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";
}
}
[更新 2] Web コンソールで以下のエラーが発生しました: Uncaught ReferrenceError: LocalFileSystem is not defined at ...
問題は何ですか?