Download WebView file Android 4.0

It just does NOT work.

I'm doing it

webView.setWebChromeClient(new WebChromeClient() { public void openFileChooser(ValueCallback<Uri> uploadFile) { System.out.println("openFileChooser"); mUploadMessage = uploadFile; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("file/*"); PresentationActivity.this.startActivityForResult( Intent.createChooser(i, "Image Browser"), FILECHOOSER_RESULTCODE); } }); 

but openFileChooser is never called. Any ideas? openFileChooser is tagged @hide in the Android source code. I think this is because you should not use this method. Is there any other way to open fileChooser?

+6
source share
1 answer

Parameters for openFileChooser were updated several times.

For Android 3.0 - 4.0 this

 public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType ) 

for 4.1,

 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) 

and for 2.x

 public void openFileChooser( ValueCallback<Uri> uploadMsg ) 

You will need to add all of them to support any device between Android 2.0 and 4.1.

+12
source

Source: https://habr.com/ru/post/917654/


All Articles