File Upload in WebView

后端 未结 19 1893
旧巷少年郎
旧巷少年郎 2020-11-22 00:28

I have been struggling to upload files from WebView since last few days and there is no progress. I googled and implemented all suggested solutions but none works, like: sol

19条回答
  •  温柔的废话
    2020-11-22 00:46

    this is the only solution that i found that works!

    WebView webview;
    
    private ValueCallback mUploadMessage;
    private final static int FILECHOOSER_RESULTCODE = 1;
    
    @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;
    
        }
    }
    
    // Next part 
    
    class MyWebChromeClient extends WebChromeClient {
        // The undocumented magic method override
        // Eclipse will swear at you if you try to put @Override here
        public void openFileChooser(ValueCallback uploadMsg) {
    
            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            Cv5appActivity.this.startActivityForResult(
                    Intent.createChooser(i, "Image Browser"),
                    FILECHOOSER_RESULTCODE);
        }
    }
    

提交回复
热议问题