我試圖通過使用HTML輸入類型文件標記從加載在android webView 中的html頁面打開android本機相機。從android webView打開相機
<input type="file" accept="image/*">
我不知道爲什麼,但相機沒有打開,我不知道該怎麼辦。
我已經嘗試了iPhone的webView的同一頁,它的工作。
我該怎麼辦?
我試圖通過使用HTML輸入類型文件標記從加載在android webView 中的html頁面打開android本機相機。從android webView打開相機
<input type="file" accept="image/*">
我不知道爲什麼,但相機沒有打開,我不知道該怎麼辦。
我已經嘗試了iPhone的webView的同一頁,它的工作。
我該怎麼辦?
如果我明白你的問題正確
你想打開Android設備上的攝像頭在網頁(HTML),點擊按鈕?
在這樣的假設的基礎上, 你需要做以下
使用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);
}
}
添加JSinterface到您的WebView
webView.addJavascriptInterface(new WebVCamBridgeInterface(), "AndroidDevice");
有以下JS在您的HTML /網頁
<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>
我提供了鏈接到示例項目的演示視頻的演示,看看。 https://drive.google.com/drive/folders/0BwRMp8dK9LMLeEo5cTlXVE9ZUW8?usp=sharing
您也可以參考這些教程
歡呼!
糾正我,如果即時通訊錯了,但你試圖從HTML頁面打開相機是正確的? – ViVekH