最近两篇都是关于WebView的,以前就觉得WebView很坑,存在各种问题,所以特别讨厌使用WebView,但是最近因为公司项目需求,不得不使用了。今天说的是WebView加载的网页中点击按钮可以调用手机相册和拍照的功能。因为WebView本身是没有这个权限的,所以需要你重写其中的方法,下面是代码:
public class MainActivity extends AppCompatActivity { private WebView mWebView; private String path="http://123.56.64.244:8082/hgjl.admin/timeline/time.html?customerid=166"; private ValueCallback<Uri> mUploadMessage;// 表单的数据信息 private ValueCallback<Uri[]> mUploadCallbackAboveL; private final static int FILECHOOSER_RESULTCODE = 1;// 表单的结果回调</span> private Uri imageUri; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = (WebView) findViewById(R.id.web); mWebView.loadUrl(path); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); WebSettings settings = mWebView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); settings.setSupportZoom(true); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideU