title: Android Webview - Upload
body: <p>I have seen the solution mentioned <a href="https://stackoverflow.com/questions/5907369/file-upload-in-webview">here</a>, but I can't figure out, how to make it work with my code.
  Here is the code (displaying simple page with file upload). My app should compatible with Android 2.3-4.1</p>
  <pre><code>package com.myapp.test;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.view.Window;
  import android.view.WindowManager;
  import android.webkit.CookieSyncManager;
  import android.webkit.ValueCallback;
  import android.webkit.WebChromeClient;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class MainActivity extends Activity {
      @Override
      public void onBackPressed() {
      }   
      
      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;
  
          }
      }
      
      
      private WebView webView;
      
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.activity_main);
          CookieSyncManager.createInstance(this);
          CookieSyncManager.getInstance().startSync();
          webView = (WebView) findViewById(R.id.webView1);
          webView.getSettings().setJavaScriptEnabled(true);
          //webView.getSettings().setUserAgentString(&quot;Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) version/4.0.4 Mobile/7B367 Safari/531.21.10&quot;);
           webView.setWebChromeClient(new WebChromeClient()
            {
                   //The undocumented magic method override
                   //Eclipse will swear at you if you try to put @Override here
                   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(&quot;image/*&quot;);
                    MainActivity.this.startActivityForResult(Intent.createChooser(i,&quot;File Chooser&quot;), FILECHOOSER_RESULTCODE);
             
                   }
            });
          
          webView.loadUrl(&quot;http://encodable.com/uploaddemo/&quot;);
          webView.setWebViewClient(new MyWebViewClient());
          }
      private class MyWebViewClient extends WebViewClient {
           @Override
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
              return false;
          }
  
      }
      
      class MyWebChromeClient extends WebChromeClient {
          // The undocumented magic method override
          // Eclipse will swear at you if you try to put @Override here
          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(&quot;image/*&quot;);
              MainActivity.this.startActivityForResult(
                      Intent.createChooser(i, &quot;Image Browser&quot;),
                      FILECHOOSER_RESULTCODE);
          }
  
  }
      
  }
  </code></pre>
  <p>I am not able to get the filechooser to open.</p>
  <p>Any ideas? I am kind of hopeless, I am doing something wrong...</p>