h5页面打开图片管理器
一般页面在pc打开文件管理器是用 type=”file”的代码,可是这在android的webview是无效的,必须为webview设定WebChromeClient代码如下:
1. mWebview.setWebChromeClient(((HomeActivity) mContext).mOpenFileWebChromeClient);
2. OpenFileWebChromeClient类中重写并添加onShowFileChooser、openFileChooser:这样才会打开文件管理器,但是还需要把选择的地址穿回到页面,具体看3.
public class OpenFileWebChromeClient extends WebChromeClient {
public static final int REQUEST_FILE_PICKER = 1;
public ValueCallback mFilePathCallback;
public ValueCallback mFilePathCallbacks;
Activity mContext;
public OpenFileWebChromeClient(Activity mContext){
super();
this.mContext = mContext;
}
// Android < 3.0 调用这个方法
public void openFileChooser(ValueCallback filePathCallback) {
mFilePathCallback = filePathCallback;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
mContext.startActivityForResult(Intent.createChooser(intent, "File Chooser"),
REQUEST_FILE_PICKER);
}
// 3.0 + 调用这个方法
public void openFileChooser(ValueCallback filePathCallback,
String acceptType) {
mFilePathCallback = filePathCallback;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
mContext.startActivityForResult(Intent.createChooser(intent, "File Chooser"),
REQUEST_FILE_PICKER);
}
// / js上传文件的事件捕获
// Android > 4.1.1 调用这个方法
public void openFileChooser(ValueCallback filePathCallback,
String acceptType, String capture) {
mFilePathCallback = filePathCallback;