List of usage examples for android.app DownloadManager STATUS_PAUSED
int STATUS_PAUSED
To view the source code for android.app DownloadManager STATUS_PAUSED.
Click Source Link
From source file:org.apache.cordova.backgroundDownload.BackgroundDownload.java
private long findActiveDownload(String uri) { DownloadManager mgr = (DownloadManager) cordova.getActivity().getSystemService(Context.DOWNLOAD_SERVICE); long downloadId = DOWNLOAD_ID_UNDEFINED; DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus(DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_SUCCESSFUL); Cursor cur = mgr.query(query); int idxId = cur.getColumnIndex(DownloadManager.COLUMN_ID); int idxUri = cur.getColumnIndex(DownloadManager.COLUMN_URI); for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { if (uri.equals(cur.getString(idxUri))) { downloadId = cur.getLong(idxId); break; }/*from w w w . j av a 2s. c o m*/ } cur.close(); return downloadId; }
From source file:com.concentricsky.android.khanacademy.util.OfflineVideoManager.java
/** * Cancel ongoing and enqueued video downloads. *//*from ww w. jav a 2 s . c o m*/ public void cancelAllVideoDownloads() { final DownloadManager dlm = getDownloadManager(); final DownloadManager.Query q = new DownloadManager.Query(); q.setFilterByStatus(DownloadManager.STATUS_FAILED | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); // Cancel all tasks - we don't want any more downloads enqueued, and we are // beginning a cancel task so we don't need any previous one. queueExecutor.shutdownNow(); queueExecutor = Executors.newSingleThreadExecutor(); new AsyncTask<Void, Void, Integer>() { @Override protected void onPreExecute() { doToast("Stopping downloads..."); } @Override protected Integer doInBackground(Void... arg) { int result = 0; if (isCancelled()) return result; Cursor c = dlm.query(q); Long[] removed = new Long[c.getCount()]; int i = 0; while (c.moveToNext()) { if (isCancelled()) break; long id = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID)); removed[i++] = id; dlm.remove(id); result++; } c.close(); UpdateBuilder<Video, String> u = videoDao.updateBuilder(); try { u.where().in("dlm_id", (Object[]) removed); u.updateColumnValue("download_status", Video.DL_STATUS_NOT_STARTED); u.update(); } catch (SQLException e) { e.printStackTrace(); } return result; } @Override protected void onPostExecute(Integer result) { if (result > 0) { doToast(result + " downloads cancelled."); } else { doToast("No downloads in queue."); } doOfflineVideoSetChanged(); } @Override protected void onCancelled(Integer result) { if (result > 0) { doToast(result + " downloads cancelled."); } doOfflineVideoSetChanged(); } }.executeOnExecutor(queueExecutor); }
From source file:com.concentricsky.android.khanacademy.util.OfflineVideoManager.java
/** * Get whether a {@link Video} has begun downloading. * //from www .j a v a2s . c o m * @param video The {@link Video} to check. * @return True if the download has begun, false otherwise. This means true if a download is complete, and false if the download is enqueued but not yet begun. */ public boolean hasDownloadBegun(Video video) { Log.d(LOG_TAG, "hasDownloadBegun"); DownloadManager.Query q = new DownloadManager.Query(); long dlm_id = video.getDlm_id(); if (dlm_id <= 0) { return false; } q.setFilterById(dlm_id); q.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_SUCCESSFUL); Cursor c = getDownloadManager().query(q); boolean result = c.getCount() > 0; c.close(); return result; }
From source file:com.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java
private boolean areDownloadsEnqueued() { DownloadManager.Query q = new DownloadManager.Query(); q.setFilterByStatus(//from ww w. ja v a2 s . co m DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); Cursor c = getDownloadManager().query(q); boolean result = c.getCount() > 0; c.close(); return result; }
From source file:com.hughes.android.dictionary.DictionaryManagerActivity.java
private synchronized void downloadDictionary(final String downloadUrl, long bytes, Button downloadButton) { String destFile;//w w w . ja v a 2 s. c o m try { destFile = new File(new URL(downloadUrl).getPath()).getName(); } catch (MalformedURLException e) { throw new RuntimeException("Invalid download URL!", e); } DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); final Cursor cursor = downloadManager.query(query); // Due to a bug, cursor is null instead of empty when // the download manager is disabled. if (cursor == null) { new AlertDialog.Builder(DictionaryManagerActivity.this).setTitle(getString(R.string.error)) .setMessage(getString(R.string.downloadFailed, R.string.downloadManagerQueryFailed)) .setNeutralButton("Close", null).show(); return; } while (cursor.moveToNext()) { if (downloadUrl.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI)))) break; if (destFile.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE)))) break; } if (!cursor.isAfterLast()) { downloadManager.remove(cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID))); downloadButton.setText(getString(R.string.downloadButton, bytes / 1024.0 / 1024.0)); cursor.close(); return; } cursor.close(); Request request = new Request(Uri.parse(downloadUrl)); Log.d(LOG, "Downloading to: " + destFile); request.setTitle(destFile); File destFilePath = new File(application.getDictDir(), destFile); destFilePath.delete(); try { request.setDestinationUri(Uri.fromFile(destFilePath)); } catch (Exception e) { } try { downloadManager.enqueue(request); } catch (SecurityException e) { request = new Request(Uri.parse(downloadUrl)); request.setTitle(destFile); downloadManager.enqueue(request); } Log.w(LOG, "Download started: " + destFile); downloadButton.setText("X"); }
From source file:org.anoopam.main.anoopamaudio.AudioListActivity.java
public static boolean isDownloading(int downloadManagerStatus) { return downloadManagerStatus == DownloadManager.STATUS_RUNNING || downloadManagerStatus == DownloadManager.STATUS_PAUSED || downloadManagerStatus == DownloadManager.STATUS_PENDING; }