当我打开我的应用程序,我使用webview时,我点击filechooser什么都没有发生。虽然我尝试在浏览器中的网站上工作。Filechooser不能在webview中工作
为什么在Android Webview中不能使用filechooser?
当我打开我的应用程序,我使用webview时,我点击filechooser什么都没有发生。虽然我尝试在浏览器中的网站上工作。Filechooser不能在webview中工作
为什么在Android Webview中不能使用filechooser?
你要实现你的code.Basically的JavaScript接口,你必须使用JavaScript和你的活动进行沟通。 请考虑此示例并根据您的需求进行更改。
https://www.opengeeks.me/2015/08/filechooser-and-android-webview/
使用此代码从设备获取文件时的WebView打开:
web.setWebChromeClient(new WebChromeClient()
{
//The undocumented magic method override
//Eclipse will swear at you if you try to put @Override here
// For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
MyWb.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
}
// For Android 3.0+
public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
MyWb.this.startActivityForResult(
Intent.createChooser(i, "File Browser"),
FILECHOOSER_RESULTCODE);
}
//For Android 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
MyWb.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MyWb.FILECHOOSER_RESULTCODE);
}
});
@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;
}
}
谢谢!这工作!超! –
我怎样才能让这个例子更多,然后只有图像。我也想上传其他文件。 –