科尔多瓦网络和照相机API返回undefined [英] Cordova Network and Camera API returns undefined
问题描述
建立我的第一个科尔多瓦4.0应用程序,我真的需要一些帮助,因为我要告诉这个应用程序的演示tmrw ...
Building my first Cordova 4.0 app, and I would really need some help since I'm gonna show a demo of this app tmrw...
当我尝试访问网络信息API和照相机API( navigator.connection
和 navigator.camera
分别),他们总是返回undefined。
When I try to access the Network info API and the Camera API (navigator.connection
and navigator.camera
respectively) they always return undefined.
我在我的Android清单这些正确的:
I have these right in my Android manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
和这里是安装的插件:
org.apache.cordova.camera 0.3.3 "Camera"
org.apache.cordova.console 0.2.11 "Console"
org.apache.cordova.device 0.2.12 "Device"
org.apache.cordova.network-information 0.2.13 "Network Information"
我也复制从平台文件夹下的 cordova.js
文件,并添加了&LT; SCRIPT TYPE =文/ JavaScript的SRC =JS / cordova.js&GT;&LT; / SCRIPT&GT;
标签来我的index.html。另外这里也正是我尝试访问摄像头API我的code的例子:
I have also copied the cordova.js
file from the platform-folder and added the <SCRIPT TYPE="text/javascript" src="js/cordova.js"></SCRIPT>
tag to my index.html. Also here's an example of my code where I try to access the camera API:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
$(document).on('click', '.camera', function(){
if (!navigator.camera) {
alert("Camera API not supported", "Error");
return;
}
var options = { quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Album
encodingType: 0 // 0=JPG 1=PNG
};
navigator.camera.getPicture( function(imgData) { return imgData; }, function() { alert('Error');}, options);
});
}
当我运行此我总是得到照相机API不支持警告,这意味着它是不确定的。
When I run this I always get the "Camera API not supported" alert, meaning it's undefined.
我是什么失踪?
推荐答案
所以,这个问题的答案是,科尔多瓦自动包含在项目的WWW cordova.js
文件上构建。因此,所有我所要做的就是包括&LT;脚本类型=文/ JavaScript的SRC =cordova.js&GT;&LT; / SCRIPT&GT;
标记。
So the answer to this question was that Cordova automatically includes the cordova.js
file in the projects www on build. So all I had to do was include the <script type="text/javascript" src="cordova.js"></script>
tag.
这是我复制 cordova.js
文件,包括到我的JS文件夹是不必要的。希望这可以帮助别人。
That is, my copying the cordova.js
file and including it into my JS-folder was unnecessary. Hope this might help somebody.
这篇关于科尔多瓦网络和照相机API返回undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!