Best code examples for Android DownloadManager class (android.app.DownloadManager)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DownloadManager class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android DownloadManager examples from Open Source projects
This code example shows how to use the following methods: getMimeTypeForDownloadedFile, getUriForDownloadedFile
This code example shows how to use the following methods: enqueue, setDestinationInExternalPublicDir
 
        // Check whether we have permission to write file to external storage. 
        // We only start download request if we have permission. 
        if (!checkWriteExternalPermission()) return; 
 
        Request request = new Request(Uri.parse(url));
        request.setDestinationInExternalPublicDir(
                Environment.DIRECTORY_DOWNLOADS, fileName);
        getDownloadManager().enqueue(request);
        popupMessages(DOWNLOAD_START_TOAST + fileName);
    } 
 
    private String getFileName(String url, String contentDisposition, String mimetype) {
        String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
        int extensionIndex = fileName.lastIndexOf(".");
        String extension = null;
        if ((extensionIndex > 1) && (extensionIndex < fileName.length())) {
            extension = fileName.substring(extensionIndex + 1);
        } 
 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getMimeTypeForDownloadedFile, getUriForDownloadedFile
This code example shows how to use the following methods: enqueue
        } else { 
            final DownloadManager manager
                    = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
            new Thread("Browser download") {
                public void run() { 
                    manager.enqueue(request);
                } 
            }.start();
        } 
        Toast.makeText(activity, R.string.download_pending, Toast.LENGTH_SHORT)
                .show(); 
    } 
 
} 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: enqueue
    } 
 
    public void testDownloadManagerRequest() { 
        // first try a minimal request 
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://localhost/path"));
        mManager.enqueue(request);
 
        // now set everything we can, save for external destintion (for which we lack permission) 
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
        request.setAllowedOverRoaming(false);
        request.setTitle("test");
        request.setDescription("test");
        request.setMimeType("text/html");
        request.addRequestHeader("X-Some-Header", "value");
        mManager.enqueue(request);
    } 
} 
Full Snippet Info
6
CodeRank
Related Android DownloadManager Questions & Answers:
See Code Examples for Android DownloadManager Methods: