Benyaman
Benyaman

Reputation: 449

Cordova/Phonegap Inappbrowser/IFrame can't open Camera on Android

Running Cordova/Phonegap 6.4.0,Android 5.0, tested with the Inappbrowser and Iframe, Both won't open up the camera but just opened up a Native file selection window. But i need to open up the camera.

<input type="file" name="fileToUpload" id="fileToUpload" accept="image/*" capture="camera">

Upvotes: 0

Views: 2216

Answers (1)

L Balsdon
L Balsdon

Reputation: 995

Edit:

I have had this issue before. It works on some devices and not others. It seem some devices use different webviews which may or may not fully support the camera input in the HTML or they expect a different syntax it seems.

For this reason I recommend using the camera plugin. As this provides a consistent result across all devices.

Cordova File Plugin:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/

Along with the Cordova File Transfer Plugin:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file-transfer/

If you just want to select images or pictures you can use the Cordova Camera Plugin

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/

Using this you can enable users to select an image from their camera

Install camera plugin:

cordova plugin add cordova-plugin-camera

Sample camera plugin JS code:

var cameraOptions = {

    destinationType: Camera.DestinationType.DATA_URL,
    sourceType: Camera.PictureSourceType.CAMERA
}

function cameraSuccess(data){

    console.log(data);

    var img = document.getElementById("yourImg");

    img.src = data;

}

function cameraError(error){

    console.log(error);

}

navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);

Sample HTML:

<div><img id="yourImg" src=""/><div>

Original

Try using this line:

<input type="file" accept="image/*;capture=camera">

Notice I have include the capture attribute inside the accept attribute.

Upvotes: 1

Related Questions