× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to enable front camera in webview for android

Naeem
Feb 26, 2015
<p>I didnt quite understand, but i thing there could one of the following two, what you want.</p> <blockquote> <p>1) access camera and just show the video on the screen(not capturing image):</p> </blockquote> <p><strong>html:</strong></p> <pre><code> &lt;canvas id='canvas' width='100' height='100'&gt;&lt;/canvas&gt; </code></pre> <p><strong>js:</strong></p> <pre><code> var onFailSoHard = function(e) { console.log('failed',e); } window.URL = window.URL || window.webkitURL ; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia; var video = document.querySelector('video'); if(navigator.getUserMedia) { navigator.getUserMedia({video: true},function(stream) { video.src = window.URL.createObjectURL(stream); },onFailSoHard); } var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); setInterval(function(){ ctx.drawImage(video,0,0); }, 100); } </code></pre> <blockquote> <p>2) capture image from the camera:</p> </blockquote> <p><a href="http://docs.phonegap.com/en/edge/cordova_camera_camera.md.html" rel="nofollow">here</a> is the <a href="http://docs.phonegap.com/en/edge/cordova_camera_camera.md.html" rel="nofollow">doc</a> for that. </p> <pre><code>navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.DATA_URL }); function onSuccess(imageData) { var image = document.getElementById('myImage'); image.src = "data:image/jpeg;base64," + imageData; } function onFail(message) { alert('Failed because: ' + message); } </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/27908670/How%20to%20enable%20front%20camera%20in%20webview%20for%20android/28025770">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus