title: Using a webview to browse the photo gallery
body: <pre><code>Min SDK API 15
  </code></pre>
  
  <p>Hello,</p>
  
  <p>I using a webview that has a button on it that will browse the apps photo gallery.</p>
  
  <p>However, when the button is clicked in the webview, nothing happens.</p>
  
  <p>The url is in the format:</p>
  
  <pre><code>https://www.xxxxxxxxxxx
  </code></pre>
  
  <p>I have added the following permissions:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.MANAGE_DOCUMENTS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;
  </code></pre>
  
  <p>I have a fragment that will load the webview in the onCreateView method (snippet only) with javascript enabled.</p>
  
  <pre><code>if(!message.isEmpty()) {            
      WebView webView = (WebView)view.findViewById(R.id.webview);
      webView.getSettings().setJavaScriptEnabled(true);
      webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
      webView.setWebViewClient(new WebViewClient());
      webView.loadUrl(message);
  }
  </code></pre>
  
  <p>I have created a simple html page to test:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Test Android Popup&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;label&gt;Test Alert 1:&lt;/label&gt;
  &lt;button type="button" onClick="alert('Test Alert Box1');"&gt;Click Me!&lt;/button&gt;
  &lt;br&gt;
  &lt;label&gt;Test Browse file&lt;/label&gt;
  &lt;input type="file" name="img"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So the url will be loaded into the webview. The webview displays a button that the user will click to browse the photos in their gallery.</p>
  
  <p>The webview looks like this:
  <img src="https://i.stack.imgur.com/E8zP7.png" alt="enter image description here"></p>
  
  <p>None of the buttons work when I click them.</p>
  
  <p>Many thanks for any suggestions,</p>
  
  <p>This code snippet works for &lt; 4.3. However, 4.4 and 5.0 it fails.</p>
  
  <pre><code> webView.setWebChromeClient(new WebChromeClient() {
              /* Open File */
              public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType, String capture) {
                  mImageFilePath = uploadMsg;
  
                  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                  intent.addCategory(Intent.CATEGORY_OPENABLE);
                  intent.setType("image/*");
  
                  startActivityForResult(intent, FILECHOOSER_RESULTCODE);
              }
  
  
              public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType) {
                  mImageFilePath = uploadMsg;
  
                  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                  intent.addCategory(Intent.CATEGORY_OPENABLE);
                  intent.setType("image/*");
  
                  startActivityForResult(intent, FILECHOOSER_RESULTCODE);
              }
  
          });
  </code></pre>