/*** * 自定义WebChromeClient,做选择图片处理 */ private ValueCallback<Uri> valueCallback; private class MyWebChromeClient extends WebChromeClient { @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { valueCallback = uploadMsg; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "完成操作需要使用"), 1); } @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { valueCallback = uploadMsg; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "完成操作需要使用"), 1); } @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg) { valueCallback = uploadMsg; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "完成操作需要使用"), 1); } @Override public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { AlertDialog.Builder b2 = new AlertDialog.Builder( MainActivity.this) .setTitle("温馨提示") .setMessage(message) .setPositiveButton("确认", new AlertDialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { result.confirm(); } }); b2.setCancelable(false); b2.create(); b2.show(); return true; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (null == valueCallback) return; Uri result = data == null || resultCode != RESULT_OK ? null : data.getData(); valueCallback.onReceiveValue(result); valueCallback = null; } }
android使用webview上传文件(图片)
最新推荐文章于 2022-05-27 17:20:29 发布