[英]Letting HTML5 access Android's camera
I want to access phone's camera using HTML5 on Android. 我想在Android上使用HTML5访问手机的相机。 Currently I have Chrome 31.0.1650.59 on Kitkat.
目前我在Kitkat上有Chrome 31.0.1650.59。
I can confirm my code working in Chrome browser on Android but I can't get it working in WebView. 我可以确认我的代码在Android上的Chrome浏览器中运行,但我无法在WebView中使用它。 I do not want to issue an intent and use default camera app.
我不想发出意图并使用默认的相机应用程序。 I want to display camera feed in WebView.
我想在WebView中显示相机Feed。
Here is my HTML code. 这是我的HTML代码。
<video id="video" width="640" height="480" autoplay></video>
<script>
window.addEventListener("DOMContentLoaded", function() {
var video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
if(navigator.webkitGetUserMedia) {
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);
</script>
Which is pretty standard. 这是非常标准的。
Here is android code which displays this page: 这是显示此页面的android代码:
WebView webView = (WebView) rootView.findViewById(R.id.webView);
WebSettings ws = webView.getSettings();
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result){
return true;
}
@Override
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
return true;
}
@Override
public boolean onJsPrompt (WebView view, String url, String message, String defaultValue, JsPromptResult result){
return true;
}
});
webView.setWebViewClient(new WebViewClient());
ws.setJavaScriptEnabled(true);
ws.setAllowFileAccess(true);
ws.setDomStorageEnabled(true);
webView.loadUrl("http://html-page.htm");
Lots of these configs have nothing to do with the problem but desperate are attempts. 很多这些配置与问题无关,但绝望是尝试。
HTML5 video accessing the local camera is only supported in Android 5 and newer. 仅在Android 5及更高版本中支持访问本地摄像头的HTML5视频。 I am currently accessing the built-in camera (Front and Back) entirely from HTML5 and some javascript, because our app will only be running on Android 5 and newer.
我目前正在完全从HTML5和一些javascript访问内置摄像头(Front和Back),因为我们的应用程序只能在Android 5及更高版本上运行。 In the back end, there is some code you can use to overrride the webview so that it will automatically accept the security prompt about allowing camera access.
在后端,您可以使用一些代码来覆盖webview,以便它自动接受有关允许摄像头访问的安全提示。 So unless you are Android 5 or newer, it won't be possible.
因此,除非您是Android 5或更新版本,否则将无法实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.