Android 4.4 WebView file chooser not opening?

后端 未结 9 494
南旧
南旧 2020-12-14 07:25

We are creating an app which uses the webview and will access a page where the user needs to upload a file. We are experiencing problems with Android 4.4 where the file choo

相关标签:
9条回答
  • 2020-12-14 07:59

    What I have done to fix this problem it is to implement CrossWalk into my project. I know the size of CrossWalk is significant (adds Chromium to your project) but I really needed this to work fine inside a native app. I documented how I implemented this in here: http://maurizionapoleoni.de/blog/implementing-a-file-input-with-camera-support-in-android-with-crosswalk/

    0 讨论(0)
  • 2020-12-14 08:01

    You need to implement a WebviewClient class. You can check these example .

    webview.setWebViewClient(new myWebClient());
    
    The web.setWebChromeClient(new WebChromeClient() {
    //
    }
    

    Create class called mywebClient and add the following code to implement onPageStarted() function, shouldOvverideLoading() function and onActivityresult() function as shown below.

    public class myWebClient extends WebViewClient { 
    
    
         @Override
         public void onPageStarted(WebView view, String url, Bitmap favicon) { 
                 super.onPageStarted(view, url, favicon);
         }
    
         @Override
    
         public boolean shouldOverrideUrlLoading(WebView view, String url) {       
    
            view.loadUrl(url);
           return true; 
         }
    
         @Override 
        public void onPageFinished(WebView view, String url) {   
            super.onPageFinished(view, url); 
        } 
     }
    
     //flipscreen not loading again
    
     @Override
    
     public void onConfigurationChanged(Configuration newConfig){  
           super.onConfigurationChanged(newConfig);
    
     } 
    
    @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; 
    
      } 
    
    }
    

    Download demo

    0 讨论(0)
  • 2020-12-14 08:05

    Found a solution that worked for me. I've added one more rule in proguard-android.txt:

    -keepclassmembers class * extends android.webkit.WebChromeClient {
         public void openFileChooser(...);
    }
    
    0 讨论(0)
提交回复
热议问题