Example usage for android.app DownloadManager COLUMN_URI

List of usage examples for android.app DownloadManager COLUMN_URI

Introduction

In this page you can find the example usage for android.app DownloadManager COLUMN_URI.

Prototype

String COLUMN_URI

To view the source code for android.app DownloadManager COLUMN_URI.

Click Source Link

Document

URI to be downloaded.

Usage

From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java

@AfterViews
void setupIssuesGrid() {
    gridView.setEmptyView(emptyGridView);
    gridView.setOnItemClickListener(new IssuesGridOnItemClickListener());

    final SimpleCursorAdapter issueListAdapter = new SimpleCursorAdapter(this, R.layout.include_issue, null,
            new String[] { DownloadManager.COLUMN_DESCRIPTION, DownloadManager.COLUMN_STATUS },
            new int[] { R.id.dateTextView, R.id.stateTextView }, 0) {

        @Override/*from w  w w .  j a  v a 2 s  .c om*/
        public View getView(final int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            View deleteButton = view.findViewById(R.id.issueDeleteButton);
            deleteButton.setOnClickListener(new IssueDeleteButtonOnClickListener(position));

            // Load the thumbnail image
            ImageView image = (ImageView) view.findViewById(R.id.issueImageView);
            Uri uri = Uri.parse(getCursor().getString(getCursor().getColumnIndex(DownloadManager.COLUMN_URI)));
            Picasso.with(image.getContext()).load(IssueDownloadService_.getThumbnailUriForPDFUri(uri))
                    .placeholder(R.drawable.issue_placeholder).into(image);
            return view;
        }
    };
    issueListAdapter.setViewBinder(new IssuesGridViewBinder(this));
    gridView.setAdapter(issueListAdapter);

    getLoaderManager().initLoader(1, null, new IssuesGridLoaderCallbacks(this, issueListAdapter));
}

From source file:com.bluros.updater.UpdatesSettings.java

@Override
protected void onStart() {
    super.onStart();

    // Determine if there are any in-progress downloads
    mDownloadId = mPrefs.getLong(Constants.DOWNLOAD_ID, -1);
    if (mDownloadId >= 0) {
        Cursor c = mDownloadManager.query(new DownloadManager.Query().setFilterById(mDownloadId));
        if (c == null || !c.moveToFirst()) {
            Toast.makeText(this, R.string.download_not_found, Toast.LENGTH_LONG).show();
        } else {//from  w w  w  .  j a  va2s. c  om
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI)));
            if (status == DownloadManager.STATUS_PENDING || status == DownloadManager.STATUS_RUNNING
                    || status == DownloadManager.STATUS_PAUSED) {
                mDownloadFileName = uri.getLastPathSegment();
            }
        }
        if (c != null) {
            c.close();
        }
    }
    if (mDownloadId < 0 || mDownloadFileName == null) {
        resetDownloadState();
    }

    requestUpdateLayout();

    IntentFilter filter = new IntentFilter(UpdateCheckService.ACTION_CHECK_FINISHED);
    filter.addAction(DownloadReceiver.ACTION_DOWNLOAD_STARTED);
    registerReceiver(mReceiver, filter);

    checkForDownloadCompleted(getIntent());
    setIntent(null);
}

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 ww .j  a  va 2s .c o  m
    }
    cur.close();

    return downloadId;
}

From source file:org.apache.cordova.backgroundDownload.BackgroundDownload.java

private Boolean checkDownloadCompleted(long id) {
    DownloadManager mgr = (DownloadManager) this.cordova.getActivity()
            .getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(id);/*from   w w  w  .  j a  v a2s . c om*/
    Cursor cur = mgr.query(query);
    int idxStatus = cur.getColumnIndex(DownloadManager.COLUMN_STATUS);
    int idxURI = cur.getColumnIndex(DownloadManager.COLUMN_URI);

    if (cur.moveToFirst()) {
        int status = cur.getInt(idxStatus);
        String uri = cur.getString(idxURI);
        Download curDownload = activDownloads.get(uri);
        if (status == DownloadManager.STATUS_SUCCESSFUL) { // TODO review what else we can have here
            copyTempFileToActualFile(curDownload);
            CleanUp(curDownload);
            return true;
        }
    }
    cur.close();

    return false;
}

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  a  va  2s  .  co  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");
}