Search in sources :

Example 31 with Query

use of android.app.DownloadManager.Query in project android_frameworks_base by crdroidandroid.

the class DownloadManagerBaseTest method getCursor.

/**
     * Performs a query based on ID and returns a Cursor for the query.
     *
     * @param id The id of the download in DL Manager; pass -1 to query all downloads
     * @return A cursor for the query results
     */
protected Cursor getCursor(long id) throws Exception {
    Query query = new Query();
    if (id != -1) {
        query.setFilterById(id);
    }
    Cursor cursor = mDownloadManager.query(query);
    int currentWaitTime = 0;
    try {
        while (!cursor.moveToFirst()) {
            Thread.sleep(DEFAULT_WAIT_POLL_TIME);
            currentWaitTime += DEFAULT_WAIT_POLL_TIME;
            if (currentWaitTime > DEFAULT_MAX_WAIT_TIME) {
                fail("timed out waiting for a non-null query result");
            }
            cursor.requery();
        }
    } catch (Exception e) {
        cursor.close();
        throw e;
    }
    return cursor;
}
Also used : Query(android.app.DownloadManager.Query) Cursor(android.database.Cursor) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 32 with Query

use of android.app.DownloadManager.Query in project android_frameworks_base by crdroidandroid.

the class DownloadManagerBaseTest method removeAllCurrentDownloads.

/**
     * Helper to remove all downloads that are registered with the DL Manager.
     *
     * Note: This gives us a clean slate b/c it includes downloads that are pending, running,
     * paused, or have completed.
     */
protected void removeAllCurrentDownloads() {
    Log.i(LOG_TAG, "Removing all current registered downloads...");
    Cursor cursor = mDownloadManager.query(new Query());
    try {
        if (cursor.moveToFirst()) {
            do {
                int index = cursor.getColumnIndex(DownloadManager.COLUMN_ID);
                long downloadId = cursor.getLong(index);
                mDownloadManager.remove(downloadId);
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
}
Also used : Query(android.app.DownloadManager.Query) Cursor(android.database.Cursor)

Example 33 with Query

use of android.app.DownloadManager.Query in project android_frameworks_base by AOSPA.

the class DownloadManagerBaseTest method removeAllCurrentDownloads.

/**
     * Helper to remove all downloads that are registered with the DL Manager.
     *
     * Note: This gives us a clean slate b/c it includes downloads that are pending, running,
     * paused, or have completed.
     */
protected void removeAllCurrentDownloads() {
    Log.i(LOG_TAG, "Removing all current registered downloads...");
    Cursor cursor = mDownloadManager.query(new Query());
    try {
        if (cursor.moveToFirst()) {
            do {
                int index = cursor.getColumnIndex(DownloadManager.COLUMN_ID);
                long downloadId = cursor.getLong(index);
                mDownloadManager.remove(downloadId);
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
}
Also used : Query(android.app.DownloadManager.Query) Cursor(android.database.Cursor)

Example 34 with Query

use of android.app.DownloadManager.Query in project android_frameworks_base by AOSPA.

the class DownloadManagerBaseTest method hasDownloadFinished.

/**
     * Checks with the download manager if the give download is finished.
     * @param id id of the download to check
     * @return true if download is finished, false otherwise.
     */
private boolean hasDownloadFinished(long id) {
    Query q = new Query();
    q.setFilterById(id);
    q.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
    Cursor cursor = mDownloadManager.query(q);
    boolean finished = cursor.getCount() == 1;
    cursor.close();
    return finished;
}
Also used : Query(android.app.DownloadManager.Query) Cursor(android.database.Cursor)

Example 35 with Query

use of android.app.DownloadManager.Query in project baker-android by bakerframework.

the class DownloaderTask method isDownloading.

public boolean isDownloading() {
    boolean result = false;
    if (null != this.dm) {
        Query query = new Query();
        query.setFilterById(downloadId);
        Cursor c = this.dm.query(query);
        try {
            if (c.getCount() > 0) {
                c.moveToFirst();
                int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
                result = (status == DownloadManager.STATUS_RUNNING);
            }
        } catch (NullPointerException ex) {
        // Do nothing
        }
    }
    return result;
}
Also used : Query(android.app.DownloadManager.Query) Cursor(android.database.Cursor)

Aggregations

Query (android.app.DownloadManager.Query)76 Cursor (android.database.Cursor)76 DownloadManager (android.app.DownloadManager)15 ArrayList (java.util.ArrayList)13 ParcelFileDescriptor (android.os.ParcelFileDescriptor)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 TimeoutException (java.util.concurrent.TimeoutException)12 File (java.io.File)11 IOException (java.io.IOException)7 Request (android.app.DownloadManager.Request)6 Uri (android.net.Uri)6 FileNotFoundException (java.io.FileNotFoundException)6 Random (java.util.Random)6