Androdi Studio setDownloadListener does not work on Android 6.0

Asked

Viewed 34 times

0

Even before version 6.0 the following method below works perfectly by downloading any document requested in Webview..

However now with android 6.0 in attempt to any download inside the webview the app hangs and says "The application has stopped working.".

The method below is in the same webview class.. Anyone knows how to download in android version 6?

//Método para download PDF
wv.setDownloadListener(new DownloadListener() {

    public void onDownloadStart(String url, String userAgent,
                                String contentDisposition, String mimetype,
                                long contentLength) {
        DownloadManager.Request request = new DownloadManager.Request(
                Uri.parse(url));

        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "boleto.pdf");
        DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        dm.enqueue(request);
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
        intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
        intent.setType("*/*");//any application,any extension
        Toast.makeText(getApplicationContext(), "Baixando Arquivo", //To notify the Client that the file is being downloaded
                Toast.LENGTH_LONG).show();

    }
});
  • 1

    Edit the question and put the log error, I’m pretty sure it’s lack of permissions.

  • 1

    I researched better at night and really that was it. The new permissions system on Android 6 was blocking.. I added the permission request to record in memory in the MAIN class and now the webview downloads files as in previous verses.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.