Java Code Examples for android.app.DownloadManager.Request#setDestinationUri()
The following examples show how to use
android.app.DownloadManager.Request#setDestinationUri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadMaster.java From uPods-android with Apache License 2.0 | 6 votes |
public void download(DownloadTask task) { //TODO better path DownloadManager downloadManager = (DownloadManager) UpodsApplication.getContext().getSystemService(Context.DOWNLOAD_SERVICE); Uri episodUri = Uri.parse(task.track.getAudeoUrl()); String trackName = GlobalUtils.getCleanFileName(task.track.getTitle()) + ".mp3"; String mediaItemName = GlobalUtils.getCleanFileName(task.mediaItem.getName()); String finalPath = PODCASTS_DOWNLOAD_DIRECTORY + "/" + mediaItemName + "/" + trackName; finalPath = Environment.getExternalStorageDirectory() + finalPath; Request request = new Request(episodUri); request.setAllowedNetworkTypes(Request.NETWORK_MOBILE | Request.NETWORK_WIFI); request.setTitle(task.track.getTitle()); request.setDescription(task.track.getSubTitle()); request.setDestinationUri(Uri.fromFile(new File(finalPath))); task.downloadId = downloadManager.enqueue(request); task.filePath = finalPath; allTasks.add(task); Logger.printInfo(DM_LOG, "Starting download episod " + trackName + " to " + finalPath); runProgressUpdater(); }
Example 2
Source File: IDownloadManagerImpl.java From edx-app-android with Apache License 2.0 | 5 votes |
@Override public synchronized long addDownload(File destFolder, String url, boolean wifiOnly, String title) { long dmid = -1; //Need to check first if the download manager service is enabled if(!isDownloadManagerEnabled()) return dmid; // skip if URL is not valid if(url == null) { // URL is null return dmid; } url = url.trim(); if (url.length() == 0) { // URL is empty return dmid; } logger.debug("Starting download: " + url); Uri target = Uri.fromFile(new File(destFolder, Sha1Util.SHA1(url))); Request request = new Request(Uri.parse(url)); request.setDestinationUri(target); request.setTitle(title); if (wifiOnly) { request.setAllowedNetworkTypes(Request.NETWORK_WIFI); } else { request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE); } dmid = dm.enqueue(request); return dmid; }
Example 3
Source File: DownloadsUtil.java From EdXposedManager with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("ResultOfMethodCallIgnored") private static DownloadInfo add(Builder b) { Context context = b.mContext; removeAllForUrl(context, b.mUrl); if (!b.mDialog) { synchronized (mCallbacks) { mCallbacks.put(b.mUrl, b.mCallback); } } String savePath = "Download/EdXposedManager"; if (b.mModule) { savePath += "/modules"; } Request request = new Request(Uri.parse(b.mUrl)); request.setTitle(b.mTitle); request.setMimeType(b.mMimeType.toString()); if (b.mSave) { try { request.setDestinationInExternalPublicDir(savePath, b.mTitle + b.mMimeType.getExtension()); } catch (IllegalStateException e) { Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } } else if (b.mDestination != null) { b.mDestination.getParentFile().mkdirs(); removeAllForLocalFile(context, b.mDestination); request.setDestinationUri(Uri.fromFile(b.mDestination)); } request.setNotificationVisibility(Request.VISIBILITY_VISIBLE); DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); long id = dm.enqueue(request); if (b.mDialog) { showDownloadDialog(b, id); } return getById(context, id); }
Example 4
Source File: DownloadMapActivity.java From PocketMaps with MIT License | 4 votes |
/** * download map * * @param view View * @param position item position */ private void onClickMapNow(int position) { MyMap myMap = myDownloadAdapter.getItem(position); if (myMap.getStatus() == MyMap.DlStatus.Downloading || myMap.getStatus() == MyMap.DlStatus.Unzipping) { logUser("Already downloading!"); return; } else if (myMap.isUpdateAvailable()) { MyMap myMapNew = null; if (!myMap.getMapNameNew().isEmpty()) { int removePos = -1; for (int i= 0; i<myDownloadAdapter.getItemCount(); i++) { if (myDownloadAdapter.getItem(i).getMapName().equals(myMap.getMapName())) { removePos = i; } if (myDownloadAdapter.getItem(i).getMapName().equals(myMap.getMapNameNew())) { position = i; myMapNew = myDownloadAdapter.getItem(i); } } if (removePos < 0 || myMapNew == null) { logUser("OldMap or NewMap missing on json-list!"); return; } mapsRV.scrollToPosition(position); myDownloadAdapter.remove(removePos); if (position > removePos) { position--; } } MainActivity.clearLocalMap(myMap); if (myMapNew != null) { myMap = myMapNew; if (myMap.getStatus() != DlStatus.On_server) { logUser("New map is: " + myMap.getMapName()); return; } } } else if (myMap.getStatus() == MyMap.DlStatus.Complete) { logUser("Already downloaded!"); return; } myMap.setStatus(MyMap.DlStatus.Downloading); myDownloadAdapter.refreshMapView(myMap); String vers = "?v=unknown"; DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); try { PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); vers = "?v=" + packageInfo.versionName; } catch (Exception e) {} // No problem, not important. Request request = new Request(Uri.parse(myMap.getUrl() + vers)); File destFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlMapFile); request.setDestinationUri(Uri.fromFile(destFile)); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setMimeType("application/pocketmaps"); long enqueueId = dm.enqueue(request); File idFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlIdFile); IO.writeToFile("" + enqueueId, idFile, false); BroadcastReceiver br = createBroadcastReceiver(this, createStatusUpdater(), myMap, enqueueId); registerReceiver(br, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); receiverList.add(br); }