title: Image preview in Android webview before upload not working
body: <p>well I m making an android webview app, Im facing an issue here.
  I m trying to preview my image on webpage before uploading
  Here is my <code>html and java script</code> code i m using.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
  
  
  &lt;script type="text/javascript"&gt;
  
  $(document).ready(function(){
      var preview = $(".upload-preview img");
  
      $(".file").change(function(event){
         var input = $(event.currentTarget);
         var file = input[0].files[0];
         var reader = new FileReader();
         reader.onload = function(e){
             image_base64 = e.target.result;
             preview.attr("src", image_base64);
         };
         reader.readAsDataURL(file);
      });
  });
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div class="upload-preview"&gt;
      &lt;img /&gt;
  &lt;/div&gt;
  &lt;input class="file" name="logo" type="file"&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>here is <a href="http://jsfiddle.net/Kulgar/57F67/" rel="nofollow noreferrer">fiddle</a></p>
  
  <p>Its working just fine on almost every browser (i.e Firefox, Chrome and IE) without any error or warning. here is snapshot of firefox (showing the preview before upload)
  <img src="https://i.stack.imgur.com/8I79s.jpg" alt="enter image description here"></p>
  
  <p><strong>Now whenever I try to open this in android webview its not showing the image preview</strong> 
  it shows something like this</p>
  
  <p><img src="https://i.stack.imgur.com/iDk9j.jpg" alt="enter image description here"></p>
  
  <p>I don't know whats wrong, I have enable the <code>javascript</code> and included the <code>jquery</code>. Its driving me crazy since one day.</p>
  
  <p>here is my android webview code.</p>
  
  <pre><code>package net.kaosfield.wv1;
  
  import my.functions.MyFunctions;
  import android.net.Uri;
  import android.os.Bundle;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.Intent;
  import android.util.Log;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.webkit.ValueCallback;
  import android.webkit.WebChromeClient;
  import android.webkit.WebViewClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.JsResult;
  import android.content.Intent;
  import com.google.android.gcm.GCMRegistrar;
  
  public class MainActivity extends Activity {
  
  Activity activity = MainActivity.this;
  
  private WebView webView = null;
  
  private ValueCallback&lt;Uri&gt; uploadMessage;
  
  private final static int FILECHOOSER_RESULTCODE = 1;
  
  private static String registrationId = "";
  
  private MyFunctions myFunctions;
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode,
          Intent intent) {
      if (requestCode == FILECHOOSER_RESULTCODE) {
          if (uploadMessage == null)
              return;
          Uri result = intent == null || resultCode != RESULT_OK ? null
                  : intent.getData();
          uploadMessage.onReceiveValue(result);
          uploadMessage = null;
      }
  }
  
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myFunctions = new MyFunctions(activity);
  
              webView = (WebView) findViewById(R.id.webview);
      webView.setInitialScale(myFunctions.setWebViewScale());
  
      WebSettings webSettings = webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webView.setWebViewClient(new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if (url.startsWith("net.kaosfield.wv1:")) {
                  Log.d("wv1", url);
                  return true;
              }
              return false;
          }
  
          @Override
          public void onPageFinished(WebView view, String url) {
              Log.d("wv1", "onPageFinished");
              String argument = "d.e.f";
              view.loadUrl("javascript:alert(window.method(\"" + argument
                      + "\"))");
          }
      });
      webView.setWebChromeClient(new WebChromeClient() {
          @Override
          public boolean onJsAlert(WebView view, String url, String message,
                  JsResult result) {
              if (message.equals("net.kaosfield.wv1")) {
                  try {
                      Log.d("wv1", "url: " + url + ", message: " + message);
                      return true;
                  } finally {
                      result.confirm(); // in order not to alert
                  }
              } else {
                  return false;
              }
          }
  
          // For Android 3.0+
          @SuppressWarnings("unused")
          public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg) {
              uploadMessage = uploadMsg;
              Intent i = new Intent(Intent.ACTION_GET_CONTENT);
              i.addCategory(Intent.CATEGORY_OPENABLE);
              i.setType("image/*");
              MainActivity.this.startActivityForResult(
                      Intent.createChooser(i, "File Chooser"),
                      FILECHOOSER_RESULTCODE);
          }
  
          // For Android 3.0+
          @SuppressWarnings("unused")
          public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg,
                  String acceptType) {
              uploadMessage = uploadMsg;
              Intent i = new Intent(Intent.ACTION_GET_CONTENT);
              i.addCategory(Intent.CATEGORY_OPENABLE);
              i.setType("image/*");
              MainActivity.this.startActivityForResult(
                      Intent.createChooser(i, "File Browser"),
                      FILECHOOSER_RESULTCODE);
          }
  
          // For Android 4.1
          @SuppressWarnings("unused")
          public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg,
                  String acceptType, String capture) {
              uploadMessage = uploadMsg;
              Intent i = new Intent(Intent.ACTION_GET_CONTENT);
              i.addCategory(Intent.CATEGORY_OPENABLE);
              i.setType("image/*");
              MainActivity.this.startActivityForResult(
                      Intent.createChooser(i, "File Chooser"),
                      MainActivity.FILECHOOSER_RESULTCODE);
          }
      });
  
       webView.loadUrl("http://blue.genetechz.com/qadir/test.php");
  }
  
  @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) {
      // Check if the key event was the Back button and if there's history
      if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; webView.canGoBack()) {
          webView.goBack();
          return true;
      }
      // If it wasn't the Back key or there's no web page history, bubble up
      // to the default
      // system behavior (probably exit the activity)
      return super.onKeyDown(keyCode, event);
  }
  
  }
  </code></pre>