0

I created​ an android application using android WebView here is the code i used to load WebView

WebView browser = (WebView) findViewById(R.id.webview);
    browser.loadUrl("http://samanretail.website/shv");
    browser.getSettings().setJavaScriptEnabled(true);
    browser.setWebViewClient(new WebViewClient());

and the problem is I can't access​ the open file option in web view. When I click open file option nothing happens ..please help me to find a solution for this.

Vivek Barai
  • 1,338
  • 13
  • 26

1 Answers1

0

try this code on your click event

WebView web = (WebView) findViewById(R.id.webview);

web = new WebView(this);  
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.yoururl.com/index.html");
web.setWebViewClient(new myWebClient());
web.setWebChromeClient(new WebChromeClient()  
{  
       //The undocumented magic method override  
       //Eclipse will swear at you if you try to put @Override here  
    // For Android 3.0+
    public void openFileChooser(ValueCallback<Uri> uploadMsg) {  

        mUploadMessage = uploadMsg;  
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
        i.addCategory(Intent.CATEGORY_OPENABLE);  
        i.setType("image/*");  
        MyWb.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);  

       }

    // For Android 3.0+
       public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
       mUploadMessage = uploadMsg;
       Intent i = new Intent(Intent.ACTION_GET_CONTENT);
       i.addCategory(Intent.CATEGORY_OPENABLE);
       i.setType("*/*");
       MyWb.this.startActivityForResult(
       Intent.createChooser(i, "File Browser"),
       FILECHOOSER_RESULTCODE);
       }

    //For Android 4.1
       public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
           mUploadMessage = uploadMsg;  
           Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
           i.addCategory(Intent.CATEGORY_OPENABLE);  
           i.setType("image/*");  
           MyWb.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MyWb.FILECHOOSER_RESULTCODE );

       }

});  


setContentView(web);  
Fakhriddin Abdullaev
  • 4,169
  • 2
  • 35
  • 37
  • it's also working thanks..... can i open camera using this webview with the same button open file chooser please hel me to do this thanks in advance – Phsyco_Developer Jun 01 '17 at 05:56