哈尔滨制作手机网站,文化传媒公司网站模板,沈阳seo顾问公司,制作app怎么制作最近h5开发一个编译器#xff0c;要在手机上显示#xff0c;需要获取手机上的图片#xff0c;使用webview不能直接到文件管理拿取#xff0c;还需要对webview做处理#xff0c;做个记录#xff0c;方便以后使用#xff1b; public ValueCallbackUri[] mUploadMe…最近h5开发一个编译器要在手机上显示需要获取手机上的图片使用webview不能直接到文件管理拿取还需要对webview做处理做个记录方便以后使用 public ValueCallbackUri[] mUploadMessageForAndroid5;
用这个方法去给定义的字段赋值并使用方法跳转到手机本地拿到图片一定要返回 true 否则会报错的
binding.webView.setWebChromeClient(new WebChromeClient(){// For Android 5.0public boolean onShowFileChooser (WebView webView, ValueCallbackUri[] uploadMsg,WebChromeClient.FileChooserParams fileChooserParams) {mUploadMessageForAndroid5 uploadMsg;onenFileChooseImpleForAndroid(uploadMsg);return true;}});
拿到用户文件返回的并返回给webview显示
Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);Uri result data.getData();mUploadMessageForAndroid5.onReceiveValue(new Uri[]{result});mUploadMessageForAndroid5 null;
}
跳转手机本地图片的方法
private void onenFileChooseImpleForAndroid(ValueCallbackUri[] filePathCallback) {mUploadMessageForAndroid5 filePathCallback;Intent contentSelectionIntent new Intent(Intent.ACTION_GET_CONTENT);contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);contentSelectionIntent.setType(image/*);Intent chooserIntent new Intent(Intent.ACTION_CHOOSER);chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);chooserIntent.putExtra(Intent.EXTRA_TITLE, Image Chooser);startActivityForResult(chooserIntent, 2);
} 以上只做了跳转拿取图片没有做文件或者视频的如果以后有用到再更新。