今天看到一我的提問,怎麼在android上用web頁面打開手機攝像頭。恰好咱們以前也作過相似的工程,恰好把想法寫一下:javascript
一、基本原理:html
二、簡單案例:java
final class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}android
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.d("WebView", "onPageStarted");
super.onPageStarted(view, url, favicon);
}web
public void onPageFinished(WebView view, String url) {
Log.d("WebView", "onPageFinished ");
view.loadUrl("javascript:window.local_obj.showSource('<head>'+"
+ "document.getElementsByTagName('html')[0].innerHTML+'</head>');");
tv_item_loading.setVisibility(View.GONE);
super.onPageFinished(view, url);api
//能夠根據不一樣的URL,作不一樣的操做
}
}瀏覽器