Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

for file picker openFileChooser() method not calling WebChromeClient of Kitkat 4.4

I have one hi-bride application in which one html page has file picker and i want to load that page in Android webview.

This pickers works well in Device browser but not in webview.

For to support this i am using one hidden method of WebChromeClient which is as below

public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){  
            /**updated, out of the IF **/
            mUploadMessage = uploadMsg;
            /**updated, out of the IF **/
            if(boolFileChooser){ //Take picture from filechooser
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
                i.addCategory(Intent.CATEGORY_OPENABLE);  
                i.setType("image/*");  
                startActivityForResult( Intent.createChooser( i, "Pick File.." ), FILECHOOSER_RESULTCODE );  
            } else { //Take photo and upload picture
                Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
                photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
                if(photo.exists())
                    photo.delete();
                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
                mCapturedImageURI = Uri.fromFile(photo);
                startActivityForResult(cameraIntent, CAMERAREQUEST_RESULTCODE);
            }
        }
    // Per Android < 3.0
        public void openFileChooser(ValueCallback<Uri> uploadMsg){
            openFileChooser(uploadMsg, "");
        }
        //Aftre
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg, "");
        }

It was working fine till 4.3 but from 4.4 this method is not getting called. And they said https://code.google.com/p/android/issues/detail?id=62220 this has been removed.

Do anyone knows any alternate way. Please let me know your help will greatly appreciated

like image 933
Yashdeep Patel Avatar asked Dec 31 '13 11:12

Yashdeep Patel


2 Answers

There are no ways to openFileChooser method after 4.3 as google has removed that and they will come up with other way to handle this file chooser stuff in next version (Confirmed by Google engineer).

I moved to hybrid architecture to and write native function for file picker.

like image 148
Yashdeep Patel Avatar answered Sep 28 '22 19:09

Yashdeep Patel


In Android 5.0, they introduced onShowFileChooser(), with which you can use an input form field in the webview and launch a file chooser to select images and files from the device.

like image 39
Daniel Avatar answered Sep 28 '22 18:09

Daniel