File Upload in WebView

后端 未结 19 1899
旧巷少年郎
旧巷少年郎 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:59

    This solution also works for Honeycomb and Ice Cream Sandwich. Seems like Google introduced a cool new feature (accept attribute) and forgot to to implement an overload for backwards compatibility.

    protected class CustomWebChromeClient extends WebChromeClient
    {
        // For Android 3.0+
        public void openFileChooser( ValueCallback uploadMsg, String acceptType ) 
        {  
            context.mUploadMessage = uploadMsg;  
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
            i.addCategory(Intent.CATEGORY_OPENABLE);  
            i.setType("image/*");  
            context.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MainActivity.FILECHOOSER_RESULTCODE );  
        }
    
        // For Android < 3.0
        public void openFileChooser( ValueCallback uploadMsg ) 
        {
            openFileChooser( uploadMsg, "" );
        }
    }
    

提交回复
热议问题