Example usage for android.app DownloadManager STATUS_PAUSED

List of usage examples for android.app DownloadManager STATUS_PAUSED

Introduction

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

Prototype

int STATUS_PAUSED

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

Click Source Link

Document

Value of #COLUMN_STATUS when the download is waiting to retry or resume.

Usage

From source file:Main.java

public static String reasonString(Cursor c) {
    String msg = "???";

    //get reason index
    Integer statusint = statusInt(c);
    Integer reasonint = reasonInt(c);
    //interpret reason index depending on status
    if (statusint == DownloadManager.STATUS_PAUSED)
        msg = REASONLISTPAUSED[reasonint];
    else if (statusint == DownloadManager.STATUS_FAILED)
        msg = REASONLISTFAILED[reasonint - 1000];

    return (msg);
}

From source file:Main.java

/**
 * Find a download with the specified name.  Returns -1 if none was
 * found.//from  w  ww  . j av a2 s  .c o  m
 */
static long findPath(DownloadManager dm, String path) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(
            DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);
    Cursor c = dm.query(query);

    if (!c.moveToFirst())
        return -1;

    final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
    final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);

    do {
        final String uri = c.getString(columnLocalURI);
        if (uri != null && uri.endsWith(path))
            return c.getLong(columnID);
    } while (c.moveToNext());

    return -1;
}

From source file:Main.java

public static void CheckDwnloadStatus(DownloadManager downloadManager, Activity activity, long id) {

    // TODO Auto-generated method stub
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(id);//from  ww w.j av a  2 s.  c o  m
    Cursor cursor = downloadManager.query(query);
    if (cursor.moveToFirst()) {
        int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
        int status = cursor.getInt(columnIndex);
        int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
        int reason = cursor.getInt(columnReason);

        switch (status) {
        case DownloadManager.STATUS_FAILED:
            String failedReason = "";
            switch (reason) {
            case DownloadManager.ERROR_CANNOT_RESUME:
                failedReason = "ERROR_CANNOT_RESUME";
                break;
            case DownloadManager.ERROR_DEVICE_NOT_FOUND:
                failedReason = "ERROR_DEVICE_NOT_FOUND";
                break;
            case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
                failedReason = "ERROR_FILE_ALREADY_EXISTS";
                break;
            case DownloadManager.ERROR_FILE_ERROR:
                failedReason = "ERROR_FILE_ERROR";
                break;
            case DownloadManager.ERROR_HTTP_DATA_ERROR:
                failedReason = "ERROR_HTTP_DATA_ERROR";
                break;
            case DownloadManager.ERROR_INSUFFICIENT_SPACE:
                failedReason = "ERROR_INSUFFICIENT_SPACE";
                break;
            case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
                failedReason = "ERROR_TOO_MANY_REDIRECTS";
                break;
            case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
                failedReason = "ERROR_UNHANDLED_HTTP_CODE";
                break;
            case DownloadManager.ERROR_UNKNOWN:
                failedReason = "ERROR_UNKNOWN";
                break;
            default:
                failedReason = "unknown reason";
                break;
            }

            Toast.makeText(activity, "FAILED: " + failedReason, Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_PAUSED:
            String pausedReason = "";

            switch (reason) {
            case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
                pausedReason = "PAUSED_QUEUED_FOR_WIFI";
                break;
            case DownloadManager.PAUSED_UNKNOWN:
                pausedReason = "PAUSED_UNKNOWN";
                break;
            case DownloadManager.PAUSED_WAITING_FOR_NETWORK:
                pausedReason = "PAUSED_WAITING_FOR_NETWORK";
                break;
            case DownloadManager.PAUSED_WAITING_TO_RETRY:
                pausedReason = "PAUSED_WAITING_TO_RETRY";
                break;
            }

            Toast.makeText(activity, "PAUSED: " + pausedReason, Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_PENDING:
            Toast.makeText(activity, "PENDING", Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_RUNNING:
            Toast.makeText(activity, "RUNNING", Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_SUCCESSFUL:

            Toast.makeText(activity, "SUCCESSFUL", Toast.LENGTH_LONG).show();
            break;
        }
    }
}

From source file:com.commonsware.android.downmgr.DownloadFragment.java

private String statusMessage(Cursor c) {
    String msg = "???";

    switch (c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
    case DownloadManager.STATUS_FAILED:
        msg = getActivity().getString(R.string.download_failed);
        break;// w  ww .  j a v a 2s  .c  o m

    case DownloadManager.STATUS_PAUSED:
        msg = getActivity().getString(R.string.download_paused);
        break;

    case DownloadManager.STATUS_PENDING:
        msg = getActivity().getString(R.string.download_pending);
        break;

    case DownloadManager.STATUS_RUNNING:
        msg = getActivity().getString(R.string.download_in_progress);
        break;

    case DownloadManager.STATUS_SUCCESSFUL:
        msg = getActivity().getString(R.string.download_complete);
        break;

    default:
        msg = getActivity().getString(R.string.download_is_nowhere_in_sight);
        break;
    }

    return (msg);
}

From source file:com.giovanniterlingen.windesheim.controllers.DownloadController.java

@Override
protected String doInBackground(final String... strings) {
    try {/*from w  w w  .j  a  v a2s. co m*/
        activeDownloads.put(contentId, new Download());
        int lastSlash = url.lastIndexOf('/');
        String fileName = url.substring(lastSlash + 1);

        File directory = Environment.getExternalStoragePublicDirectory(
                ApplicationLoader.applicationContext.getResources().getString(R.string.app_name));
        if (!directory.exists()) {
            directory.mkdirs();
        }

        final String encodedUrl = new URI("https", "elo.windesheim.nl", url, null).toString();

        downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(encodedUrl));
        request.addRequestHeader("Cookie", new CookieController().getNatSchoolCookie()).setTitle(fileName)
                .setDescription(activity.getResources().getString(R.string.downloading))
                .setDestinationInExternalPublicDir(File.separator
                        + ApplicationLoader.applicationContext.getResources().getString(R.string.app_name),
                        fileName);

        currentDownloadId = downloadManager.enqueue(request);
        while (true) {
            if (isCancelled()) {
                return "cancelled";
            }
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(currentDownloadId);
            Cursor cursor = downloadManager.query(query);
            if (cursor.getCount() == 0) {
                return "cancelled";
            }
            cursor.moveToFirst();
            int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
            if (status == DownloadManager.STATUS_SUCCESSFUL || status == DownloadManager.STATUS_FAILED) {
                break;
            }
            if (status == DownloadManager.STATUS_PAUSED || status == DownloadManager.STATUS_PENDING) {
                // paused, reset download state to pending
                activeDownloads.put(contentId, new Download());
                NotificationCenter.getInstance().postNotificationName(NotificationCenter.downloadPending,
                        studyRouteId, adapterPosition, contentId);
                Thread.sleep(100);
                continue;
            }
            long downloaded = cursor
                    .getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
            long total = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
            cursor.close();
            if (total > 0 && downloaded > 0) {
                int progress = (int) (downloaded * 100 / total);
                String s = Formatter.formatFileSize(activity, downloaded) + "/"
                        + Formatter.formatFileSize(activity, total);
                activeDownloads.get(contentId).setProgress(progress);
                activeDownloads.get(contentId).setProgressString(s);
                publishProgress(progress, s);
            }
            Thread.sleep(100);
        }
        return new File(directory, fileName).getAbsolutePath();
    } catch (SecurityException e) {
        return "permission";
    } catch (Exception e) {
        return null;
    }
}

From source file:com.example.linhdq.test.main_menu.language.OCRLanguageActivity.java

private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) {
    if (adapter != null) {
        // find languages that are currently being downloaded
        Query query = new Query();
        query.setFilterByStatus(DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING
                | DownloadManager.STATUS_PAUSED);
        final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        Cursor c = dm.query(query);
        if (c == null) {
            return;
        }//from  w  ww  . j  a  va 2s  . c  o m
        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
        while (c.moveToNext()) {
            final String title = c.getString(columnIndex);
            adapter.setDownloading(title, true);
        }
        adapter.notifyDataSetChanged();
        c.close();
    }
}

From source file:com.cypher.cota.helpers.DownloadHelper.java

private static long[] getDownloadProgress(long id) {
    DownloadManager.Query q = new DownloadManager.Query();
    q.setFilterById(id);//from w ww.  j  a  v a 2 s. co m

    Cursor cursor = sDownloadManager.query(q);
    int status;

    if (cursor == null || !cursor.moveToFirst()) {
        status = DownloadManager.STATUS_FAILED;
    } else {
        status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
    }

    long error = -1;
    long totalBytes = -1;
    long downloadedBytes = -1;

    switch (status) {
    case DownloadManager.STATUS_PAUSED:
    case DownloadManager.STATUS_RUNNING:
        downloadedBytes = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
        totalBytes = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
        break;
    case DownloadManager.STATUS_FAILED:
        sDownloadingRom = false;
        error = getDownloadError(cursor);
        break;
    }

    if (cursor != null) {
        cursor.close();
    }

    return new long[] { status, totalBytes, downloadedBytes, error };
}

From source file:com.renard.ocr.help.OCRLanguageActivity.java

private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) {
    if (adapter != null) {
        // find languages that are currently beeing downloaded
        Query query = new Query();
        query.setFilterByStatus(DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING
                | DownloadManager.STATUS_PAUSED);
        final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        Cursor c = dm.query(query);
        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
        while (c.moveToNext()) {
            final String title = c.getString(columnIndex);
            adapter.setDownloading(title, true);
        }/*  ww w  .j ava  2 s.  c om*/
        adapter.notifyDataSetChanged();
        c.close();
    }
}

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   www .  j  a va2s.c  o m
            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:scal.io.liger.LigerDownloadManager.java

public boolean checkQueue() {

    String fileName = ZipHelper.getExpansionZipFilename(context, mainOrPatch, version);
    String filePath = ZipHelper.getExpansionZipDirectory(context, mainOrPatch, version);

    File checkFile = new File(filePath, fileName + ".tmp");
    boolean foundInQueue = false;

    // need to check if a download has already been queued for this file
    //HashMap<Long, QueueItem> queueMap = QueueManager.loadQueue(context);

    //for (Long queueId : queueMap.keySet()) {

    //Timber.d("QUEUE ITEM IS " + queueMap.get(queueId).getQueueFile() + " LOOKING FOR " + checkFile.getName());

    //if (checkFile.getName().equals(queueMap.get(queueId).getQueueFile())) {

    Long queueId = QueueManager.checkQueue(context, checkFile);

    if (queueId == null) {

        // not found
        foundInQueue = false;/*ww w  . j a va2s .  c  om*/

    } else if (queueId.equals(QueueManager.DUPLICATE_QUERY)) {

        // not exactly in queue, but someone is already looking for this item, so avoid collision
        foundInQueue = true;

    } else if (queueId < 0) {
        // use negative numbers to flag non-manager downloads

        if (checkFileProgress()) {

            Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " AND DOWNLOAD PROGRESS OBSERVED, LEAVING "
                    + queueId.toString() + " IN QUEUE ");
            foundInQueue = true;

        } else {

            Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                    + " BUT NO DOWNLOAD PROGRESS OBSERVED, REMOVING " + queueId.toString() + " FROM QUEUE ");
            QueueManager.removeFromQueue(context, Long.valueOf(queueId));

        }

    } else {
        // use download manager ids to flag manager downloads

        // need to init download manager to check queue
        initDownloadManager();

        DownloadManager.Query query = new DownloadManager.Query();
        query.setFilterById(queueId.longValue());
        Cursor c = dManager.query(query);
        try {
            if (c.moveToFirst()) {

                int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                if (DownloadManager.STATUS_FAILED == c.getInt(columnIndex)) {

                    Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                            + " BUT DOWNLOAD STATUS IS FAILED, REMOVING " + queueId.toString()
                            + " FROM QUEUE ");
                    QueueManager.removeFromQueue(context, Long.valueOf(queueId));

                } else if (DownloadManager.STATUS_PAUSED == c.getInt(columnIndex)) {

                    Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                            + " AND DOWNLOAD STATUS IS PAUSED, LEAVING " + queueId.toString() + " IN QUEUE ");
                    foundInQueue = true;

                } else if (DownloadManager.STATUS_PENDING == c.getInt(columnIndex)) {

                    Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                            + " AND DOWNLOAD STATUS IS PENDING, LEAVING " + queueId.toString() + " IN QUEUE ");
                    foundInQueue = true;

                } else if (DownloadManager.STATUS_RUNNING == c.getInt(columnIndex)) {

                    Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                            + " AND DOWNLOAD STATUS IS RUNNING, LEAVING " + queueId.toString() + " IN QUEUE ");
                    foundInQueue = true;

                } else if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {

                    Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                            + " BUT DOWNLOAD STATUS IS SUCCESSFUL, REMOVING " + queueId.toString()
                            + " FROM QUEUE ");
                    QueueManager.removeFromQueue(context, Long.valueOf(queueId));

                } else {

                    Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                            + " BUT DOWNLOAD STATUS IS UNKNOWN, REMOVING " + queueId.toString()
                            + " FROM QUEUE ");
                    QueueManager.removeFromQueue(context, Long.valueOf(queueId));

                }
            } else {

                Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName()
                        + " BUT NOTHING FOUND IN DOWNLOAD MANAGER, REMOVING " + queueId.toString()
                        + " FROM QUEUE ");
                QueueManager.removeFromQueue(context, Long.valueOf(queueId));

            }
        } finally {
            if (c != null) {
                c.close();
            }
        }

        // cleanup
        c.close();
    }
    //}

    // skipping timeout check for now, timeout duration undecided

    /*
    if (foundInQueue) {
        Date currentTime = new Date();
        long queuedTime = queueMap.get(queueId).getQueueTime();
        if ((currentTime.getTime() - queueMap.get(queueId).getQueueTime()) > QueueManager.queueTimeout) {
            
            Timber.d("TIMEOUT EXCEEDED, REMOVING " + queueId.toString() + " FROM DOWNLOAD MANAGER.");
            int numberRemoved = manager.remove(queueId);
            
            if (numberRemoved == 1) {
                Timber.d("REMOVED FROM DOWNLOAD MANAGER, RE-QUEUEING: " + queueId.toString() + " -> " + uriFile.toString());
                QueueManager.removeFromQueue(context, Long.valueOf(queueId));
                foundInQueue = false;
            } else {
                Timber.d("FAILED TO REMOVE FROM DOWNLOAD MANAGER, NOT QUEUEING: " + queueId.toString() + " -> " + uriFile.toString());
            }
        }
    }
    */
    //}

    return foundInQueue;
}