Android 4.4 WebView file chooser not opening?

后端 未结 9 541
南旧
南旧 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 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

提交回复
热议问题