Here are the examples of the java api class android.app.DownloadManager.Request taken from open source projects.
1. TrackDownloaderImpl#createDownloadRequest()
Project: scdl
File: TrackDownloaderImpl.java
File: TrackDownloaderImpl.java
/** * Creates a new download manager request based on the given uri. * * @param uri * @return * @throws IOException If directory can't be used for saving the file. */ @TargetApi(11) private DownloadManager.Request createDownloadRequest(final Uri uri) throws IOException { final Request request = new Request(uri); setRequestStorage(request); request.setTitle(mTrack.getTitle()); request.setDescription(mContext.getString(R.string.download_description)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // We have an audio file, please scan it! request.allowScanningByMediaScanner(); } return request; }
2. AdvancedWebView#handleDownload()
Project: Android-AdvancedWebView
File: AdvancedWebView.java
File: AdvancedWebView.java
/** * Handles a download by loading the file from `fromUrl` and saving it to `toFilename` on the external storage * * This requires the two permissions `android.permission.INTERNET` and `android.permission.WRITE_EXTERNAL_STORAGE` * * Only supported on API level 9 (Android 2.3) and above * * @param context a valid `Context` reference * @param fromUrl the URL of the file to download, e.g. the one from `AdvancedWebView.onDownloadRequested(...)` * @param toFilename the name of the destination file where the download should be saved, e.g. `myImage.jpg` * @return whether the download has been successfully handled or not */ @SuppressLint("NewApi") public static boolean handleDownload(final Context context, final String fromUrl, final String toFilename) { if (Build.VERSION.SDK_INT < 9) { throw new RuntimeException("Method requires API level 9 or above"); } final Request request = new Request(Uri.parse(fromUrl)); if (Build.VERSION.SDK_INT >= 11) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, toFilename); final DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); try { try { dm.enqueue(request); } catch (SecurityException e) { if (Build.VERSION.SDK_INT >= 11) { request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE); } dm.enqueue(request); } return true; }// if the download manager app has been disabled on the device catch (IllegalArgumentException e) { openAppSettings(context, AdvancedWebView.PACKAGE_NAME_DOWNLOAD_MANAGER); return false; } }
3. DownloadManagerActivity#onClick()
Project: codeexamples-android
File: DownloadManagerActivity.java
File: DownloadManagerActivity.java
public void onClick(View view) { dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Request request = new Request(Uri.parse("http://www.vogella.de/img/lars/LarsVogelArticle7.png")); enqueue = dm.enqueue(request); }