我正在尝试type="file"在移动设备上的应用程序中打开输入文件选择器WebView,但处理同一问题的其他问题给出的解决方案适用于早期的 Android 版本,并且似乎不适用于 Android 9。问题似乎出在这段特定的代码就在这里:
//For Lollipop 5.0+ Devices:
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
{
if (uploadMessage != null) {
uploadMessage.onReceiveValue(null);
uploadMessage = null;
}
uploadMessage = filePathCallback;
Intent intent = fileChooserParams.createIntent();
try
{
startActivityForResult(intent, REQUEST_SELECT_FILE);
} catch (ActivityNotFoundException e)
{
uploadMessage = null;
Toast.makeText(MainActivity.this, "Error: Unable to open file browser", Toast.LENGTH_LONG).show();
return false;
}
return true;
}
收到一只叮咚
相关分类