除了Lollipop版本之外,Android Webview中的文件选择器无法正常工作

时间:2017-02-20 18:41:14

标签: android webview webchromeclient

  

我尝试了很多通过WebView上传文件,但我没有成功,   但它仅使用5.0设备。

     

谷歌Chrome浏览器处理所有事情&在所有设备上都能正常工作。

public class MyWebChromeClient extends WebChromeClient {

    public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, FileChooserParams fileChooserParams) {

        mFilePathCallback = filePath;

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(intent, PICKFILE_REQUEST_CODE);
   return true;

    }

    public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("*/*");
        startActivityForResult(
                Intent.createChooser(i, "File Browser"),
                PICKFILE_REQUEST_CODE);
    }

    //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("*/*");
        startActivityForResult( Intent.createChooser( i, "File Chooser" ), PICKFILE_REQUEST_CODE );

    }

0 个答案:

没有答案