Example usage for android.app DownloadManager COLUMN_REASON

List of usage examples for android.app DownloadManager COLUMN_REASON

Introduction

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

Prototype

String COLUMN_REASON

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

Click Source Link

Document

Provides more detail on the status of the download.

Usage

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  .co 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:Main.java

public static Integer reasonInt(Cursor c) {
    return c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
}

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

private void queryStatus(View v) {
    Cursor c = mgr.query(new DownloadManager.Query().setFilterById(lastDownload));

    if (c == null) {
        Toast.makeText(getActivity(), R.string.download_not_found, Toast.LENGTH_LONG).show();
    } else {/*from  w w w  .  j ava 2s.  co m*/
        c.moveToFirst();

        Log.d(getClass().getName(), "COLUMN_ID: " + c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID)));
        Log.d(getClass().getName(), "COLUMN_BYTES_DOWNLOADED_SO_FAR: "
                + c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)));
        Log.d(getClass().getName(), "COLUMN_LAST_MODIFIED_TIMESTAMP: "
                + c.getLong(c.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP)));
        Log.d(getClass().getName(),
                "COLUMN_LOCAL_URI: " + c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)));
        Log.d(getClass().getName(),
                "COLUMN_STATUS: " + c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)));
        Log.d(getClass().getName(),
                "COLUMN_REASON: " + c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)));

        Toast.makeText(getActivity(), statusMessage(c), Toast.LENGTH_LONG).show();

        c.close();
    }
}

From source file:org.openbmap.activities.DialogPreferenceCatalogs.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *//*www .  j  a v  a 2s  .  com*/
@SuppressLint("NewApi")
private void initDownloadManager() {
    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:org.openbmap.activities.DialogPreferenceMaps.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *///from  w ww . ja  v a  2s. c o  m
@SuppressLint("NewApi")
private void initDownloadManager() {

    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

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

private static int getDownloadError(Cursor cursor) {
    int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
    int reasonText;
    try {/*from   w w w  . j  av  a  2 s . com*/
        int reason = cursor.getInt(columnReason);
        switch (reason) {
        case DownloadManager.ERROR_CANNOT_RESUME:
            reasonText = R.string.error_cannot_resume;
            break;
        case DownloadManager.ERROR_DEVICE_NOT_FOUND:
            reasonText = R.string.error_device_not_found;
            break;
        case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
            reasonText = R.string.error_file_already_exists;
            break;
        case DownloadManager.ERROR_FILE_ERROR:
            reasonText = R.string.error_file_error;
            break;
        case DownloadManager.ERROR_HTTP_DATA_ERROR:
            reasonText = R.string.error_http_data_error;
            break;
        case DownloadManager.ERROR_INSUFFICIENT_SPACE:
            reasonText = R.string.error_insufficient_space;
            break;
        case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
            reasonText = R.string.error_too_many_redirects;
            break;
        case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
            reasonText = R.string.error_unhandled_http_code;
            break;
        case DownloadManager.ERROR_UNKNOWN:
        default:
            reasonText = R.string.error_unknown;
            break;
        }
    } catch (CursorIndexOutOfBoundsException ex) {
        // don't crash, just report it
        reasonText = R.string.error_unknown;
    }
    return reasonText;
}

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

private void StartProgressTracking(final Download curDownload) {
    // already started
    if (curDownload.getTimerProgressUpdate() != null) {
        return;/*from w ww  .  j a  va2 s  .co  m*/
    }
    final DownloadManager mgr = (DownloadManager) this.cordova.getActivity()
            .getSystemService(Context.DOWNLOAD_SERVICE);

    curDownload.setTimerProgressUpdate(new Timer());
    curDownload.getTimerProgressUpdate().schedule(new TimerTask() {
        @Override
        public void run() {
            DownloadManager.Query q = new DownloadManager.Query();
            q.setFilterById(curDownload.getDownloadId());
            Cursor cursor = mgr.query(q);
            if (cursor.moveToFirst()) {
                long bytesDownloaded = cursor
                        .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
                long bytesTotal = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
                if (bytesTotal != -1) {
                    Log.d("BackgroundDownload", "DOWNLOAD STARTED for " + curDownload.getDownloadId());
                    try {
                        JSONObject jsonProgress = new JSONObject();
                        jsonProgress.put("bytesReceived", bytesDownloaded);
                        jsonProgress.put("totalBytesToReceive", bytesTotal);
                        JSONObject obj = new JSONObject();
                        obj.put("progress", jsonProgress);
                        PluginResult progressUpdate = new PluginResult(PluginResult.Status.OK, obj);
                        progressUpdate.setKeepCallback(true);
                        curDownload.getCallbackContextDownloadStart().sendPluginResult(progressUpdate);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else {
                    long status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
                    long reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
                    Log.d("BackgroundDownload", "download not started for " + curDownload.getTempFilePath()
                            + " (status " + status + ") (reason " + reason + ")");
                }
            }
            cursor.close();
        }
    }, DOWNLOAD_PROGRESS_UPDATE_TIMEOUT, DOWNLOAD_PROGRESS_UPDATE_TIMEOUT);
}