How to download pdf file from url into download folder in internal storage

for downloading any pdf file you need to first get permission of inertnal storage after that call this method on click of butto



Step 1: Call this Method on botton click

DownloadBooks("www.androidshortcode.com/newpdffile.pdf","pdf21614051767067")

Step 2: patse this method in activity


public void DownloadBooks(String url, String title) {
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
        request.setTitle(title);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title);
        DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        request.setMimeType("application/pdf");
        request.allowScanningByMediaScanner();
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
        Toast.makeText(this, "Download Started ...", Toast.LENGTH_SHORT).show();
        downloadManager.enqueue(request);

    }

Thank You Keep Learning Keep Connected #AndroidShortCode

Comments