Reputation: 121
I'd like to capture an image using my phones camera, I have installed the plugin 'org.apache.cordova.camera' and all the permissions should come automatically, even though, I checked, and they did.
From what I understand, all I need is a button calling the javascript
<button id="photo" class="camera-control" onclick="capturePhoto()">Capture Photo</button>
and ofc, the script itself
function capturePhoto(){
navigator.camera.getPicture(cameraSuccess,null{sourceType:1,quality:60}); }
I am doing this for android (using HTC one m8), am I missing something super obvious?
Upvotes: 0
Views: 398
Reputation: 4246
It seems when success/error callbacks are not defined and passed to getPicture method then cordova camera plugin works not as expected a reason could be that in the js-file it is not checked whether successCallback and errorCallback are passed and so not undefined. if there are no callbacks passed the plugin might not be able to start calling native camera on a certain platform(Android,IOS, WP8) because wherever success/error callback are used within native code the plugin is not able to call one or either of them.
An example of Android:
On Android there is a method:
public void failPicture(String err) {
this.callbackContext.error(err);
}
That is used to call passed error callback if for instance the currently taken picture(bitmap) could not be compressed using JPEG-Image compression processing.
Defining both success/error callbacks for every plugin should always be done because if there has been an error thrown within native environment/code your webview-app can be notified by this error and so presenting appropriate UI/Message to an user.
Hope this helps.
Upvotes: 1