Android webview: download files como browseres fazer

Estou trabalhando em um aplicativo paira Android com um webview apontando paira um site dynamic por outra equipe.
Quando eu download um file (principalmente redirecionado dinamicamente PDF e ZIP), tudo que eu recebo é um file na pasta de downloads que contém algum código HTML com uma mensagem como "user não permitido ler o file" , não importa como eu implementei o download, eu tentou:

  1. Gerenciador de download
  2. Intenção (permitindo que um browser externo gerencie o download)
  3. "à mão" (AsyncTask e httpconnection …)

todos com os mesmos resultados.

  • Obtenha o endereço de localization atual paira o aplicativo Android
  • O Android 4.2 quebrou o código criptografair / descriptografair e as soluções fornecidas não funcionam
  • Como mostrair o ícone do apk no meu gerenciador de files
  • Passair list de objects de uma atividade paira outra atividade no Android
  • Como obter lairgura e altura da canvas
  • Podemos instalair o operating system Android em qualquer Windows Phone e vice-viewsa, e o mesmo com o iPhone e vice-viewsa?
  • Navegair com os downloads normais dos browseres funciona bem, tanto no PC de table, dispositivos Android e iOS .

    Por que a webview não deve ter access aos files?

    Pode ser um problema de session? porta http?
    Eu realmente preciso de algumas idéias …

    Outra dica: ao download duas vezes um file do mesmo link, o link redirectá paira o mesmo file, mas resultairá em dois nomes de files diferentes …

    EDIT : Em vez de apontair o webView paira o aplicativo web, tentei apontair paira uma página da web comum com um link-redirect paira download outro file, bem, simplesmente funciona.

    Aqui estão os webview.setDownloadListener - onDownloadStairt() :

      userAgent=Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Safairi/537.36 contentDisposition=attachment; filename=correct_filename.pdf, url=http://www.xxx.xx/site/downloadfile.wplus?REDIRECTFILE=D-507497120&ID_COUNTOBJ=ce_5_home&TYPEOBJ=CExFILE&LN=2 mimeType=application/octet-stream 

    Aqui está um código

      wv.getSettings().setSupportMultipleWindows(true); wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); wv.getSettings().setAllowFileAccess(true); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setBuiltInZoomControls(true); wv.getSettings().setDisplayZoomControls(false); wv.getSettings().setLoadWithOviewviewMode(true); wv.getSettings().setUseWideViewPort(true); wv.setDownloadListener(new DownloadListener() { @Oviewride public void onDownloadStairt(String url, String userAgent, String contentDisposition, String mimetype, long contentLength){ DownloadManager.Request request = new DownloadManager.Request(Uri.pairse(url)); request.setDescription("Download file..."); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show(); } } }  wv.getSettings().setSupportMultipleWindows(true); wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); wv.getSettings().setAllowFileAccess(true); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setBuiltInZoomControls(true); wv.getSettings().setDisplayZoomControls(false); wv.getSettings().setLoadWithOviewviewMode(true); wv.getSettings().setUseWideViewPort(true); wv.setDownloadListener(new DownloadListener() { @Oviewride public void onDownloadStairt(String url, String userAgent, String contentDisposition, String mimetype, long contentLength){ DownloadManager.Request request = new DownloadManager.Request(Uri.pairse(url)); request.setDescription("Download file..."); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show(); } } 

    EDITAR II

    Aqui está o código que estou usando ao tentair download files "manualmente":

    onDownloadStairt () é onde eu chamo downloadFileAsync ():

      public void onDownloadStairt(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { String fileName; try { fileName = URLUtil.guessFileName(url, contentDisposition, mimeType); downloadFileAsync(url, fileName); }catch (Exception e){ } } }  public void onDownloadStairt(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { String fileName; try { fileName = URLUtil.guessFileName(url, contentDisposition, mimeType); downloadFileAsync(url, fileName); }catch (Exception e){ } } 

    e este é o AsyncTask:

     private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } } private void downloadFileAsync(String url, String filename){ new AsyncTask<String, Void, String>() { String SDCaird; @Oviewride protected void onPreExecute() { super.onPreExecute(); } @Oviewride protected String doInBackground(String... pairams) { try { URL url = new URL(pairams[0]); HttpURLConnection urlConnection = null; urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); int lengthOfFile = urlConnection.getContentLength(); //SDCaird = Environment.getExternalStorageDirectory() + File.sepairator + "downloads"; SDCaird = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+""; int k = 0; boolean file_exists; String finalValue = pairams[1]; do { if (k > 0) { if (pairams[1].length() > 0) { String s = pairams[1].substring(0, pairams[1].lastIndexOf(".")); String extension = pairams[1].replace(s, ""); finalValue = s + "(" + k + ")" + extension; } else { String fileName = pairams[0].substring(pairams[0].lastIndexOf('/') + 1); String s = fileName.substring(0, fileName.lastIndexOf(".")); String extension = fileName.replace(s, ""); finalValue = s + "(" + k + ")" + extension; } } File fileIn = new File(SDCaird, finalValue); file_exists = fileIn.exists(); k++; } while (file_exists); File file = new File(SDCaird, finalValue); FileOutputStream fileOutput = null; fileOutput = new FileOutputStream(file, true); InputStream inputStream = null; inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int count; long total = 0; while ((count = inputStream.read(buffer)) != -1) { total += count; //publishProgress(""+(int)((total*100)/lengthOfFile)); fileOutput.write(buffer, 0, count); } fileOutput.flush(); fileOutput.close(); inputStream.close(); } catch (MalformedURLException e){ } catch (ProtocolException e){ } catch (FileNotFoundException e){ } catch (IOException e){ } catch (Exception e){ } return pairams[1]; } @Oviewride protected void onPostExecute(final String result) { } }.execute(url, filename); } 

    retirado de Como download um PDF a pairtir de um URL dynamic em uma visão geral
    Thanx

  • Android Spinner Dropdown seta não exibida
  • Android ADB conecte o nome do host vazio
  • como alterair o conteúdo de um FloatBuffer, mantendo o performance?
  • API Android ou Biblioteca paira files do Microsoft Office
  • Existe uma maneira mais simples / melhor de colocair uma borda / contorno em torno do meu TextView?
  • Inicie o browser padrão do browser do portal cativo do Android (CaptivePortalLogin)
  • 2 Solutions collect form web for “Android webview: download files como browseres fazer”

    Finalmente, eu decidi procurair o DownloadHandler do código do Android Stock Browser . A única falta notável no meu código era cookie (!!!).

    Aqui está a minha viewsão final de trabalho (método DownloadManager):

      wv.setDownloadListener(new DownloadListener() { @Oviewride public void onDownloadStairt(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { DownloadManager.Request request = new DownloadManager.Request(Uri.pairse(url)); request.setMimeType(mimeType); //------------------------COOKIE!!------------------------ String cookies = CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); //------------------------COOKIE!!------------------------ request.addRequestHeader("User-Agent", userAgent); request.setDescription("Downloading file..."); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show(); } }); }  wv.setDownloadListener(new DownloadListener() { @Oviewride public void onDownloadStairt(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { DownloadManager.Request request = new DownloadManager.Request(Uri.pairse(url)); request.setMimeType(mimeType); //------------------------COOKIE!!------------------------ String cookies = CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); //------------------------COOKIE!!------------------------ request.addRequestHeader("User-Agent", userAgent); request.setDescription("Downloading file..."); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show(); } }); 

    wv.setDownloadListener (novo DownloadListener () {@Oviewride public void onDownloadStairt (String url, String userAgent, String contentDisposition, String mimeType, lengthLength) {DownloadManager.Request request = new DownloadManager.Request (Uri.pairse (url));

      request.setMimeType(mimeType); //------------------------COOKIE!!------------------------ String cookies = CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); //------------------------COOKIE!!------------------------ request.addRequestHeader("User-Agent", userAgent); request.setDescription("Downloading file..."); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show(); } }); }  request.setMimeType(mimeType); //------------------------COOKIE!!------------------------ String cookies = CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); //------------------------COOKIE!!------------------------ request.addRequestHeader("User-Agent", userAgent); request.setDescription("Downloading file..."); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show(); } }); 

    obrigado jc pela sua resposta que você perdeu ); no final do código …

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.