List of usage examples for android.app DownloadManager STATUS_PENDING
int STATUS_PENDING
To view the source code for android.app DownloadManager STATUS_PENDING.
Click Source Link
From source file:com.concentricsky.android.khanacademy.util.OfflineVideoManager.java
/** * Cancel ongoing and enqueued video downloads. *///from w ww .ja v a2 s. co 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: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 a v a2 s.co 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.app.ManageDownloadsActivity.java
private boolean areDownloadsEnqueued() { DownloadManager.Query q = new DownloadManager.Query(); q.setFilterByStatus(//from www .ja 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;/*from w w w. j av 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; }