无法让 android webview 打开 android 上的文件选择器 9

Can't get android webview to open the file selector on android 9

我正在尝试在移动设备上的 WebView 应用程序中打开输入 type="file" 文件选择器,但针对处理同一问题的其他问题给出的解决方案是针对较早的 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;
    }

已在此处使用此代码修复。

        // 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
            {
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*,video/*,audio/*,file/*");
                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;
        }