title: Take a picture and upload directly in response to a "Choose File" button in a WebView
body: <p>I'm using a WebView for a simple app that let's users upload pictures on a website. I currently have a "Image Chooser" pop up when a user clicks on the "Choose file" part of the form on my website. </p>
  
  <p>I would rather the user be asked to choose an action (Camera, Gallery, File Manager). This already happens when a user is using a browser, but not in the WebView. How do I do it?</p>
  
  <p>My existing code is as follows : </p>
  
  <pre><code>package com.example.test;
  
  import android.net.Uri;
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.view.View;
  import android.webkit.ValueCallback;
  import android.webkit.WebChromeClient;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Button;
  
  public class MainActivity extends Activity {
  
  
  private WebView mWebView;
  
  private ValueCallback&lt;Uri&gt; mUploadMessage;
  private final static int FILECHOOSER_RESULTCODE = 1;
  
  @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;
  
      }
  }
  
  protected class MyWebChromeClient extends WebChromeClient {
      public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg) {  
  
          mUploadMessage = uploadMsg;  
          Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
          i.addCategory(Intent.CATEGORY_OPENABLE);  
          i.setType("image/*");  
          MainActivity.this.startActivityForResult(Intent.createChooser(i,"Image Chooser"), FILECHOOSER_RESULTCODE);  
         }
  
         public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType) {
             openFileChooser(uploadMsg);
         }                   
  
         public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType, String capture) {
             openFileChooser(uploadMsg);
         }      
  }
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mWebView = (WebView) findViewById(R.id.webview);
      mWebView.getSettings().setJavaScriptEnabled(true);
      mWebView.loadUrl("http://test.com");
      mWebView.setWebViewClient(new HelloWebViewClient());
      mWebView.setWebChromeClient(new MyWebChromeClient());
      Button newButton = (Button)findViewById(R.id.button1);
      newButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
              MainActivity.this.mWebView.loadUrl("http://test.com");
             }});
  }
  
  private class HelloWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView webview, String url){
          webview.loadUrl(url);
          return true;
      }
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event)
  {
      if ((keyCode == KeyEvent.KEYCODE_BACK)&amp;&amp; mWebView.canGoBack()){
          mWebView.goBack();
          return true;
      }
      return super.onKeyDown(keyCode, event);
  }
  }
  </code></pre>