title: Android WebView Download
body: <p>So, i have webview with some photos, and i want to add download button on them so i can save them on mobile.
  Problem is when i click on button i get full size image and it is not downloading.
  I tried to use:</p>
  
  <pre><code>mWebView.setDownloadListener(new DownloadListener() {
      public void onDownloadStart(String url, String userAgent,
                  String contentDisposition, String mimetype,
                  long contentLength) {
          Intent i = new Intent(Intent.ACTION_VIEW);
          i.setData(Uri.parse(url));
          startActivity(i);
      }
  });
  </code></pre>
  
  <p>but it is not working.</p>
  
  <p>My code is simple:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      private WebView mWebView;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mWebView = (WebView) findViewById(R.id.webview);
          WebView myWebView = (WebView) findViewById(R.id.webview);
          myWebView.loadUrl("http://someurl.com");
          WebSettings webSettings = myWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          myWebView.setWebViewClient(new WebViewClient());
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if (event.getAction() == KeyEvent.ACTION_DOWN) {
              switch (keyCode) {
                  case KeyEvent.KEYCODE_BACK:
                      if (mWebView.canGoBack()) {
                          mWebView.goBack();
                      } else {
                          finish();
                      }
                      return true;
              }
  
          }
          return super.onKeyDown(keyCode, event);
      }
  }
  </code></pre>
  
  <p>On website, code for downloading is:</p>
  
  <pre><code>&lt;a href="&lt;?php echo $_SESSION['img']; ?&gt;" download&gt;
   &lt;div id="download"&gt;
    &lt;img width="45" height="45" src="img/download.png"&gt;
   &lt;/div&gt;
  &lt;/a&gt;
  </code></pre>