Cordoba Network and Camera API returns undefined

I’m building my first Cordova 4.0 application and I really need help, as I will show a demo version of this tmrw application ...

When I try to access the network and camera APIs ( navigator.connection and navigator.camera respectively), they always return undefined.

I have this 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" /> 

And here are the installed plugins:

 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" 

I also copied the cordova.js file from the platform folder and added the <SCRIPT TYPE="text/javascript" src="js/cordova.js"></SCRIPT> to my index.html. Also here is an example of my code where I am trying 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); }); } 

When I run this, I always get the warning "Camera API not supported", which means undefined.

What am I missing?

0
source share
1 answer

So the answer to this question was that Cordoba automatically includes the cordova.js file in www on build projects. So all I had to do was include the <script type="text/javascript" src="cordova.js"></script> .

That is, my copying the cordova.js file and including it in my JS folder was unnecessary. Hope this can help someone.

+1
source

Source: https://habr.com/ru/post/1235677/


All Articles