Thi*_*993 5 html javascript android webview
我正在尝试使用 HTML 输入类型文件标签从加载在 android webView 中的 html 页面打开 android 本机相机。
<input type="file" accept="image/*">
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但相机没有打开,我不知道该怎么办。
我已经在 iPhone webView 上尝试了相同的页面并且它正在工作。
我能做什么?
如果我正确理解你的问题
您想通过单击网页(html)中的按钮来打开 Android 设备摄像头吗?
基于该假设,您需要执行以下操作
使用Javascript 接口
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);
}
}
Run Code Online (Sandbox Code Playgroud)
将 JSinterface 添加到您的 webview
webView.addJavascriptInterface(new WebVCamBridgeInterface (), "AndroidDevice");
Run Code Online (Sandbox Code Playgroud)
在你的html/网页中有以下JS
<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>
Run Code Online (Sandbox Code Playgroud)
我提供了带有演示视频的示例项目的链接,请观看。 https://drive.google.com/drive/folders/0BwRMp8dK9LMLeEo5cTlXVE9ZUW8?resourcekey=0-6dEjytPymBZvebmmyy9ymQ&usp=sharing
您还可以参考这些教程
干杯!。
| 归档时间: |
|
| 查看次数: |
5626 次 |
| 最近记录: |