admin管理员组文章数量:1391925
I'm trying to open the android native camera from an html page loaded in a android webView by using HTML input type file tag.
<input type="file" accept="image/*">
I have no idea why but the camera is not opening and I don't know what to do.
I've tried the same page on a iPhone webView and it's working.
What can I do?
I'm trying to open the android native camera from an html page loaded in a android webView by using HTML input type file tag.
<input type="file" accept="image/*">
I have no idea why but the camera is not opening and I don't know what to do.
I've tried the same page on a iPhone webView and it's working.
What can I do?
Share Improve this question edited Jan 10, 2017 at 14:20 usr30911 2,7817 gold badges32 silver badges58 bronze badges asked Jan 9, 2017 at 17:54 Thingdou1993Thingdou1993 511 silver badge2 bronze badges 1- correct me if im wrong but your trying to open the camera from a html page correct? – usr30911 Commented Jan 10, 2017 at 13:26
1 Answer
Reset to default 4If i understand your question correctly
You want to open the android device camera on click of a button in the webpage(html)?
On the basis of that assumption, You need to do the following
Use a JavascriptInterface
public class WebVCamBridgeInterface {
/**
* Javacript function to start native camera
*/
@JavascriptInterface
public void takePicture() {
captureImage();
}
/**
* Javascript function to start the GalleryActivity for user to choose the image to be uploaded
*/
@JavascriptInterface
public void showPictures() {
Intent intent = new Intent(LandingActivity.this, GalleryActivity.class);
startActivityForResult(intent, Constants.REQ_GALLERY);
}
}
add JSinterface to your webview
webView.addJavascriptInterface(new WebVCamBridgeInterface (), "AndroidDevice");
Have the following JS in your html/web page
<script>
function takePicture() {
if(typeof AndroidDevice !== "undefined"){
AndroidDevice.takePicture();
}
}
function showPictures() {
if(typeof AndroidDevice !== "undefined"){
AndroidDevice.showPictures();
}
}
function imageData(data){
document.getElementById('displayImage').setAttribute( 'src', 'data:image/png;base64,'+data );
if(typeof AndroidDevice !== "undefined"){
}
}
</script>
Im providing the link to a sample project with video of a demo ,have a look. https://drive.google./drive/folders/0BwRMp8dK9LMLeEo5cTlXVE9ZUW8?resourcekey=0-6dEjytPymBZvebmmyy9ymQ&usp=sharing
You can also refer these tutorials
Upload Image/File from Gallery or Camera in WebView in Android
Android Smart WebView with advanced features
Open File Chooser with camera option in webview
cheers!.
本文标签: javascriptOpening camera from android webViewStack Overflow
版权声明:本文标题:javascript - Opening camera from android webView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744600274a2615027.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论