今天看到一个人提问,怎么在android上用web页面打开手机摄像头。刚好我们之前也做过类似的工程,刚好把想法写一下:
1、基本原理:
2、简单案例:
final class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.d("WebView", "onPageStarted");
super.onPageStarted(view, url, favicon);
}
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);
//可以根据不同的URL,做不同的操作
}
}
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(url_site);
webView是WebView的对象
来源:oschina
链接:https://my.oschina.net/u/1024047/blog/132991