Sebastian M Sebastian M - 10 months ago 39
HTML Question

Phonegap camera doesn't work

My Android app need to takes picture but Camera plugin doesn't work. When I click on the button nothing happens.


<!DOCTYPE html>
<title>Capture Photo</title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"/>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
function onDeviceReady() {
function capturePhoto()
{, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });

function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;

function onFail(message) {
alert('Failed because: ' + message);

<button onclick="capturePhoto()">Capture</button> <br>
<button onclick="onDeviceReady()">alert</button> <br>
<img id="myImage" src="" />

I added second button only to check if button works(and it does).


<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns= ""
xmlns:gap= ""
id= "testaplikacji"
versionCode= "1"
version = "1.0.0" >
<description>Camera test</description>
<gap:platform name="android" />
<gap:plugin name="org.apache.cordova.dialogs" />
<gap:plugin name="" />
<gap:plugin name="cordova-plugin-camera" />

<feature name="Camera">
<param name="android-package" value="" />

<access origin="*"/>
<gap:config-file platform="android" parent="/manifest" mode="add" xmlns:android="">
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


I tried with and without permissions. I tried different plugins. I tried with this gist:

And also code from this tutorial:

Nothing works. I waste a lot of time trying to make this works. Please help me.


I have tested this with the phonegap build server and the HTML code you supplied works (with the change from my other answer) when using this minimal config.xml file with your html file. Also, be sure not to upload the phonegap.js in the Zip archive to the build server. An extra one will be added automatically during the build.

<?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns   = ""
        xmlns:gap   = ""
        id          = "com.stackoverflow.example.SO37227132"
        versionCode = "10" 
        version     = "1.0.0" >

    <!-- versionCode is optional and Android only -->

    <name>PhoneGap Example</name>

        An example for phonegap build docs. 

    <author href="" email="">
        Hardeep Shoker 

    <platform name="android" />
    <plugin name="" source="pgb" />