List of usage examples for android.app DownloadManager STATUS_RUNNING
int STATUS_RUNNING
To view the source code for android.app DownloadManager STATUS_RUNNING.
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; }/* w w w . j a v a 2 s. co m*/ } cur.close(); return downloadId; }
From source file:com.concentricsky.android.khanacademy.util.OfflineVideoManager.java
/** * Cancel ongoing and enqueued video downloads. *///from w w w . ja v a 2s . com 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:fr.kwiatkowski.apktrack.ui.AppViewHolder.java
/** * Sets the right status icon when the app is currently downloading or has downloaded an APK. * @param info The object containing the information about the download. * @param ctx The context of the application. * @return Whether an icon was set./* w ww. j av a 2 s . c o m*/ */ private boolean _set_action_icon_download(final DownloadInfo info, final Context ctx) { switch (info.get_status()) { case DownloadManager.STATUS_SUCCESSFUL: // APK was downloaded. Install on click. File apk = new File(info.get_local_path()); if (apk.exists()) { _action_icon.setImageDrawable(ContextCompat.getDrawable(ctx, R.drawable.install)); _action_icon.setVisibility(View.VISIBLE); _action_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse(info.get_local_uri()), "application/vnd.android.package-archive"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (i.resolveActivity(ctx.getPackageManager()) != null) { ctx.startActivity(i); } else { Log.v(MainActivity.TAG, "Could not find anyone to receive ACTION_VIEW for " + "the downloaded APK. (" + info.get_local_uri() + ")"); } } }); return true; } else { // For some reason the APK is not present anymore. Remove the download information. return false; } case DownloadManager.STATUS_PENDING: case DownloadManager.STATUS_RUNNING: _action_icon.setImageDrawable(ContextCompat.getDrawable(ctx, android.R.drawable.stat_sys_download)); ((Animatable) _action_icon.getDrawable()).start(); _action_icon.setVisibility(View.VISIBLE); return true; default: return false; } }
From source file:com.concentricsky.android.khanacademy.util.OfflineVideoManager.java
/** * Get whether a {@link Video} has begun downloading. * //ww w . j av 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(/*w w w . j a v a2 s . c o 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. j a v a2 s .c om*/ 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; }