【发布时间】:2017-10-10 05:04:07
【问题描述】:
我有一个使用 WebView 的应用程序,如果用户想上传图片,我想向他展示我们在 google chrome 中看到的内部存储选项,如图所示
这是我正在使用的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == mUploadMessage)
return;
Uri result = intent == null || resultCode != RESULT_OK ? null
: intent.getData();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
openFileChooser();
return true;
}
// The undocumented magic method override
// Eclipse will swear at you if you try to put @Override here
public void openFileChooser() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image");
MainActivity.this.startActivityForResult(
Intent.createChooser(i, "Image Browser"),
FILECHOOSER_RESULTCODE);
}
}
【问题讨论】:
-
你试过用
i.setType("*/*");替换i.setType("image");吗? -
i.setType("image/*");这对我有用,谢谢你的努力
-
在具有 android 4.4.2 操作系统的设备中进行测试。如果它不起作用,请尝试stackoverflow.com/questions/28600165/… this。
标签: android webview image-uploading