Thursday, January 29, 2015

PhoneGap plugins: Media-capture - photo

media-capture plugin needed.
Install it with this: 

phonegap plugin add org.apache.cordova.media-capture

Here is my example.html(within javascript code).
This prvides capability to start default system application for photo recording and save your photo into default locale location(displaying it into a javascript alert):

<!DOCTYPE html>
<html>
  <head>
    <title>PhoneGap Capture Image Example Page</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Called when capture operation is finished
    //
    function captureSuccess(mediaFiles) {
        var i, len;
        for (i = 0, len = mediaFiles.length; i < len; i += 1) {         
            alert (mediaFiles[i].fullPath + " e " + mediaFiles[i].name);
        }      
    }

    // Called if something bad happens.
    //
    function captureError(error) {
        var msg = 'An error occurred during capture: ' + error.code;
        navigator.notification.alert(msg, null, 'Uh oh!');
    }

    function captureImage() {
        // Launch device camera application,
        // allowing user to capture up to 2 audio clips
        navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 2});
    }
    </script>
    </head>
    <body>
        <button onclick="captureImage();">Capture Image</button> <br>
    </body>
</html>


Bye... 

No comments:

Post a Comment