PhoneGap:未定义navigator.device的捕获插件 [英] PhoneGap: Capture plugin with navigator.device undefined

查看:88
本文介绍了PhoneGap:未定义navigator.device的捕获插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PhoneGap的新手,正在尝试弄清楚如何使用捕获插件.我正在使用Cordova 3.5.0.我已成功运行以下命令:

I'm new to PhoneGap and am trying to figure out how to use the capture plugin. I'm using Cordova 3.5.0. I have run the following command successfully:

cordova plugin add org.apache.cordova.media-capture

我已经阅读了HTML页面中包含cordova.js或phonegap.js的示例.但是,Cordova创建的项目层次结构中都没有文件,因此我不知道如何包含它.我还读到了该文件是在构建时由Cordova自动注入的.因此,就包括任何JavaScript文件而言,我仅包括自己的JavaScript文件.在该JavaScript文件中,我具有用于测试目的的代码:

I have read examples where a cordova.js or a phonegap.js is being included in the HTML page. However, neither file exists in the project hierarchy that Cordova has created so I don't know how to include it. I've also read that this file is automatically injected by Cordova at build time. So as far as including any JavaScript files, I'm only including my own JavaScript file. Inside that JavaScript file I have code that does this for testing purposes:

alert(navigator.device);
navigator.device.capture.captureImage(function(files) {
    alert(files);
}, function(error) {
    alert(error);
});

第一个警报显示navigator.device未定义.我正在android模拟器上运行此应用程序.要运行该应用程序,我正在做:

The first alert shows that navigator.device is undefined. I'm running this app on the android emulator. To run the app, I'm doing:

cordova emulate android

我认为我需要包含或设置一些东西才能使它工作.任何帮助将不胜感激.

I assume there's something I need to include or setup in order to get this working. Any help is greatly appreciated.

推荐答案

我发现我需要在HTML页面中添加以下内容:

I figured out I needed to add the following to my HTML page:

<script type="text/javascript" src="cordova.js"></script>

尽管该文件在项目层次结构中不存在,但是在构建应用程序时会生成该文件.该文件不会自动注入到HTML页面中,但仍需要在需要的位置手动添加.

Although the file does not exist in the project hierarchy, it gets generated when you build the app. The file does not get injected into your HTML pages automatically, it still needs to be manually included where desired.

这篇关于PhoneGap:未定义navigator.device的捕获插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆