title: “Unfortunately, … has stopped” when Downloading file from Android Webview app in certain device
body: <p>In my android Web view app I used code below to download file from app. It's working well  and I can download file on my Samsung J2 (Android 5.2.2. API 22) ( but when I'm trying download any file from Symphony i10 ( Android 6. API 23) it “Unfortunately, … has stopped”. I didn't try with any other device. But I tried from Android Emulator ( virtual device API 24 and API 26). Same problem showing.</p>
  
  <p>How can I solve this problem?</p>
  
  <p>Main Activity:</p>
  
  <pre><code>wv.setWebViewClient(new WebViewClient(){
  
  
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
              boolean value = true;
              String extension = MimeTypeMap.getFileExtensionFromUrl(url);
              if (extension != null) {
                  MimeTypeMap mime = MimeTypeMap.getSingleton();
                  String mimeType = mime.getMimeTypeFromExtension(extension);
                  if (mimeType != null) {
                      if (mimeType.toLowerCase().contains("pdf")                                                           
  
                              || extension.toLowerCase().contains("jpeg")
                              || extension.toLowerCase().contains("jpg")
                              || extension.toLowerCase().contains("png")                        
  
  
  
                              ) {
                          DownloadManager mdDownloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
                          DownloadManager.Request request = new DownloadManager.Request(
                                  Uri.parse(url));
                          String name= URLUtil.guessFileName(url,null,MimeTypeMap.getFileExtensionFromUrl(url));
                          File destinationFile = new File(Environment.getExternalStorageDirectory(),name);
                          request.setDescription("Downloading...");
                          request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                          // request.setDestinationUri(Uri.fromFile(destinationFile));
                          request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,name);
                          mdDownloadManager.enqueue(request);
                          //value = false;
                      }
                  }
  
  
                  if (!url.contains("my site url")) { // Could be cleverer and use a regex
  
                      Intent intent = new Intent(Intent.ACTION_VIEW);
                      intent.setData(Uri.parse(url)); // only used based on your example.
                      String title = "Select a browser";
                      // Create intent to show the chooser dialog
                      Intent chooser = Intent.createChooser(intent, title);
                      // Verify the original intent will resolve to at least one activity
                      // Verify the intent will resolve to at least one activity
                      if (intent.resolveActivity(getPackageManager()) != null) {
                          startActivity(chooser);
                      }
  
                      return true;
                  }
                  return false;
              }
              return false;
  
          }
  
  
          @Override
          public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)  {
              wv.loadUrl(mypage_error);
          }
      });
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;      
  &lt;uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" /&gt;
  </code></pre>
  
  <p>gradle:</p>
  
  <pre><code>android {
  compileSdkVersion 25
  buildToolsVersion "25.0.3"
  defaultConfig {
      applicationId "com.my.app"
      minSdkVersion 15
      targetSdkVersion 25
      versionCode 5
      versionName '3.5'
      testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  </code></pre>
  
  <p>SDK</p>
  
  <p><a href="https://i.stack.imgur.com/sng9T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sng9T.png" alt="enter image description here"></a></p>
  
  <p>Note that <a href="https://stackoverflow.com/questions/45730791/webview-app-how-to-download-a-file-inside-webview-app-external-link-should-op">my previous question is here</a> like this: files will download mentioned above (extension) and except my site url all link should open mobile browser. Bu I didn't get answer that's why I used code below to warn before opening external link. </p>
  
  <pre><code>if (!url.contains("my site url")) { // Could be cleverer and use a regex
  
                      Intent intent = new Intent(Intent.ACTION_VIEW);
                      intent.setData(Uri.parse(url)); // only used based on your example.
                      String title = "Select a browser";
                      // Create intent to show the chooser dialog
                      Intent chooser = Intent.createChooser(intent, title);
                      // Verify the original intent will resolve to at least one activity
                      // Verify the intent will resolve to at least one activity
                      if (intent.resolveActivity(getPackageManager()) != null) {
                          startActivity(chooser);
                      }
  
                      return true;
  </code></pre>