Java Code Examples for android.app.DownloadManager#ERROR_FILE_ERROR

The following examples show how to use android.app.DownloadManager#ERROR_FILE_ERROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChromeDownloadDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Check the external storage and notify user on error.
 *
 * @param fullDirPath The dir path to download a file. Normally this is external storage.
 * @param externalStorageStatus The status of the external storage.
 * @return Whether external storage is ok for downloading.
 */
private boolean checkExternalStorageAndNotify(
        String filename, String fullDirPath, String externalStorageStatus) {
    if (fullDirPath == null) {
        Log.e(TAG, "Download failed: no SD card");
        alertDownloadFailure(
                filename, DownloadManager.ERROR_DEVICE_NOT_FOUND);
        return false;
    }
    if (!externalStorageStatus.equals(Environment.MEDIA_MOUNTED)) {
        int reason = DownloadManager.ERROR_DEVICE_NOT_FOUND;
        // Check to see if the SDCard is busy, same as the music app
        if (externalStorageStatus.equals(Environment.MEDIA_SHARED)) {
            Log.e(TAG, "Download failed: SD card unavailable");
            reason = DownloadManager.ERROR_FILE_ERROR;
        } else {
            Log.e(TAG, "Download failed: no SD card");
        }
        alertDownloadFailure(filename, reason);
        return false;
    }
    return true;
}
 
Example 2
Source File: ChromeDownloadDelegate.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Check the external storage and notify user on error.
 *
 * @param fullDirPath The dir path to download a file. Normally this is external storage.
 * @param externalStorageStatus The status of the external storage.
 * @return Whether external storage is ok for downloading.
 */
private boolean checkExternalStorageAndNotify(
        String filename, File fullDirPath, String externalStorageStatus) {
    if (fullDirPath == null) {
        Log.e(TAG, "Download failed: no SD card");
        alertDownloadFailure(
                filename, DownloadManager.ERROR_DEVICE_NOT_FOUND);
        return false;
    }
    if (!externalStorageStatus.equals(Environment.MEDIA_MOUNTED)) {
        int reason = DownloadManager.ERROR_DEVICE_NOT_FOUND;
        // Check to see if the SDCard is busy, same as the music app
        if (externalStorageStatus.equals(Environment.MEDIA_SHARED)) {
            Log.e(TAG, "Download failed: SD card unavailable");
            reason = DownloadManager.ERROR_FILE_ERROR;
        } else {
            Log.e(TAG, "Download failed: no SD card");
        }
        alertDownloadFailure(filename, reason);
        return false;
    }
    return true;
}
 
Example 3
Source File: ChromeDownloadDelegate.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Check the external storage and notify user on error.
 *
 * @param fullDirPath The dir path to download a file. Normally this is external storage.
 * @param externalStorageStatus The status of the external storage.
 * @return Whether external storage is ok for downloading.
 */
private boolean checkExternalStorageAndNotify(
        String filename, File fullDirPath, String externalStorageStatus) {
    if (fullDirPath == null) {
        Log.e(TAG, "Download failed: no SD card");
        alertDownloadFailure(
                filename, DownloadManager.ERROR_DEVICE_NOT_FOUND);
        return false;
    }
    if (!externalStorageStatus.equals(Environment.MEDIA_MOUNTED)) {
        int reason = DownloadManager.ERROR_DEVICE_NOT_FOUND;
        // Check to see if the SDCard is busy, same as the music app
        if (externalStorageStatus.equals(Environment.MEDIA_SHARED)) {
            Log.e(TAG, "Download failed: SD card unavailable");
            reason = DownloadManager.ERROR_FILE_ERROR;
        } else {
            Log.e(TAG, "Download failed: no SD card");
        }
        alertDownloadFailure(filename, reason);
        return false;
    }
    return true;
}
 
Example 4
Source File: DownloadManagerService.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a download fails.
 *
 * @param fileName Name of the download file.
 * @param reason Reason of failure reported by android DownloadManager
 */
protected void onDownloadFailed(String fileName, int reason) {
    String reasonString = mContext.getString(
            R.string.download_failed_reason_unknown_error, fileName);
    switch (reason) {
        case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
            reasonString = mContext.getString(
                    R.string.download_failed_reason_file_already_exists, fileName);
            break;
        case DownloadManager.ERROR_FILE_ERROR:
            reasonString = mContext.getString(
                    R.string.download_failed_reason_file_system_error, fileName);
            break;
        case DownloadManager.ERROR_INSUFFICIENT_SPACE:
            reasonString = mContext.getString(
                    R.string.download_failed_reason_insufficient_space, fileName);
            break;
        case DownloadManager.ERROR_CANNOT_RESUME:
        case DownloadManager.ERROR_HTTP_DATA_ERROR:
            reasonString = mContext.getString(
                    R.string.download_failed_reason_network_failures, fileName);
            break;
        case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
        case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
            reasonString = mContext.getString(
                    R.string.download_failed_reason_server_issues, fileName);
            break;
        case DownloadManager.ERROR_DEVICE_NOT_FOUND:
            reasonString = mContext.getString(
                    R.string.download_failed_reason_storage_not_found, fileName);
            break;
        case DownloadManager.ERROR_UNKNOWN:
        default:
            break;
    }
    mDownloadSnackbarController.onDownloadFailed(
            reasonString, reason == DownloadManager.ERROR_FILE_ALREADY_EXISTS);
}
 
Example 5
Source File: DownloadManagerService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Get the message to display when a download fails.
 *
 * @param fileName Name of the download file.
 * @param reason Reason of failure reported by android DownloadManager.
 */
private String getDownloadFailureMessage(String fileName, int reason) {
    switch (reason) {
        case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
            return mContext.getString(
                    R.string.download_failed_reason_file_already_exists, fileName);
        case DownloadManager.ERROR_FILE_ERROR:
            return mContext.getString(
                    R.string.download_failed_reason_file_system_error, fileName);
        case DownloadManager.ERROR_INSUFFICIENT_SPACE:
            return mContext.getString(
                    R.string.download_failed_reason_insufficient_space, fileName);
        case DownloadManager.ERROR_CANNOT_RESUME:
        case DownloadManager.ERROR_HTTP_DATA_ERROR:
            return mContext.getString(
                    R.string.download_failed_reason_network_failures, fileName);
        case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
        case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
            return mContext.getString(
                    R.string.download_failed_reason_server_issues, fileName);
        case DownloadManager.ERROR_DEVICE_NOT_FOUND:
            return mContext.getString(
                    R.string.download_failed_reason_storage_not_found, fileName);
        case DownloadManager.ERROR_UNKNOWN:
        default:
            return mContext.getString(
                    R.string.download_failed_reason_unknown_error, fileName);
    }
}
 
Example 6
Source File: DownloadManagerService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Get the message to display when a download fails.
 *
 * @param fileName Name of the download file.
 * @param reason Reason of failure reported by android DownloadManager.
 */
private String getDownloadFailureMessage(String fileName, int reason) {
    switch (reason) {
        case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
            return mContext.getString(
                    R.string.download_failed_reason_file_already_exists, fileName);
        case DownloadManager.ERROR_FILE_ERROR:
            return mContext.getString(
                    R.string.download_failed_reason_file_system_error, fileName);
        case DownloadManager.ERROR_INSUFFICIENT_SPACE:
            return mContext.getString(
                    R.string.download_failed_reason_insufficient_space, fileName);
        case DownloadManager.ERROR_CANNOT_RESUME:
        case DownloadManager.ERROR_HTTP_DATA_ERROR:
            return mContext.getString(
                    R.string.download_failed_reason_network_failures, fileName);
        case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
        case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
            return mContext.getString(
                    R.string.download_failed_reason_server_issues, fileName);
        case DownloadManager.ERROR_DEVICE_NOT_FOUND:
            return mContext.getString(
                    R.string.download_failed_reason_storage_not_found, fileName);
        case DownloadManager.ERROR_UNKNOWN:
        default:
            return mContext.getString(
                    R.string.download_failed_reason_unknown_error, fileName);
    }
}
 
Example 7
Source File: Downloader.java    From react-native-simple-download-manager with MIT License 4 votes vote down vote up
private HashMap<String, String> getDownloadStatus(Cursor cursor, long downloadId) {

        int columnStatusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
        int STATUS = cursor.getInt(columnStatusIndex);
        int columnReasonIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
        int REASON = cursor.getInt(columnReasonIndex);
        int filenameIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
        String filename = cursor.getString(filenameIndex);

        String statusText = "";
        String reasonText = "";

        switch (STATUS) {
            case DownloadManager.STATUS_FAILED:
                statusText = "STATUS_FAILED";
                switch (REASON) {
                    case DownloadManager.ERROR_CANNOT_RESUME:
                        reasonText = "ERROR_CANNOT_RESUME";
                        break;
                    case DownloadManager.ERROR_DEVICE_NOT_FOUND:
                        reasonText = "ERROR_DEVICE_NOT_FOUND";
                        break;
                    case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
                        reasonText = "ERROR_FILE_ALREADY_EXISTS";
                        break;
                    case DownloadManager.ERROR_FILE_ERROR:
                        reasonText = "ERROR_FILE_ERROR";
                        break;
                    case DownloadManager.ERROR_HTTP_DATA_ERROR:
                        reasonText = "ERROR_HTTP_DATA_ERROR";
                        break;
                    case DownloadManager.ERROR_INSUFFICIENT_SPACE:
                        reasonText = "ERROR_INSUFFICIENT_SPACE";
                        break;
                    case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
                        reasonText = "ERROR_TOO_MANY_REDIRECTS";
                        break;
                    case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
                        reasonText = "ERROR_UNHANDLED_HTTP_CODE";
                        break;
                    default:
                        reasonText = "ERROR_UNKNOWN";
                        break;
                }
                break;
            case DownloadManager.STATUS_PAUSED:
                statusText = "STATUS_PAUSED";
                switch (REASON) {
                    case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
                        reasonText = "PAUSED_QUEUED_FOR_WIFI";
                        break;
                    case DownloadManager.PAUSED_UNKNOWN:
                        reasonText = "PAUSED_UNKNOWN";
                        break;
                    case DownloadManager.PAUSED_WAITING_FOR_NETWORK:
                        reasonText = "PAUSED_WAITING_FOR_NETWORK";
                        break;
                    case DownloadManager.PAUSED_WAITING_TO_RETRY:
                        reasonText = "PAUSED_WAITING_TO_RETRY";
                        break;
                    default:
                        reasonText = "UNKNOWN";
                }
                break;
            case DownloadManager.STATUS_PENDING:
                statusText = "STATUS_PENDING";
                break;
            case DownloadManager.STATUS_RUNNING:
                statusText = "STATUS_RUNNING";
                break;
            case DownloadManager.STATUS_SUCCESSFUL:
                statusText = "STATUS_SUCCESSFUL";
                reasonText = filename;
                break;
            default:
                statusText = "STATUS_UNKNOWN";
                reasonText = String.valueOf(STATUS);
                break;
        }

        HashMap<String, String> result = new HashMap<>();
        result.put("status", statusText);
        result.put("reason", reasonText);
        result.put("downloadId", String.valueOf(downloadId));
        return result;
    }
 
Example 8
Source File: DownloadInfo.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public static String getReasonDebugString(int status, int reason) {
    String reasonText = "unKnown_status";
    switch (status) {
        case DownloadManager.STATUS_FAILED:
            switch (reason) {
                case DownloadManager.ERROR_CANNOT_RESUME:
                    reasonText = "ERROR_CANNOT_RESUME";
                    break;
                case DownloadManager.ERROR_DEVICE_NOT_FOUND:
                    reasonText = "(ERROR_DEVICE_NOT_FOUND)";
                    break;
                case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
                    reasonText = "(ERROR_FILE_ALREADY_EXISTS)";
                    break;
                case DownloadManager.ERROR_FILE_ERROR:
                    reasonText = "(ERROR_FILE_ERROR)";
                    break;
                case DownloadManager.ERROR_HTTP_DATA_ERROR:
                    reasonText = "(ERROR_HTTP_DATA_ERROR)";
                    break;
                case DownloadManager.ERROR_INSUFFICIENT_SPACE:
                    reasonText = "(ERROR_INSUFFICIENT_SPACE)";
                    break;
                case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
                    reasonText = "(ERROR_TOO_MANY_REDIRECTS)";
                    break;
                case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
                    reasonText = "(ERROR_UNHANDLED_HTTP_CODE)";
                    break;
                case DownloadManager.ERROR_UNKNOWN:
                    reasonText = "(ERROR_UNKNOWN)";
                    break;
            }
            break;
        case DownloadManager.STATUS_PAUSED: {
            switch (reason) {
                case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
                    reasonText = "PAUSED_QUEUED_FOR_WIFI";
                    break;
                case DownloadManager.PAUSED_UNKNOWN:
                    reasonText = "PAUSED_UNKNOWN";
                    break;
                case DownloadManager.PAUSED_WAITING_FOR_NETWORK:
                    reasonText = "PAUSED_WAITING_FOR_NETWORK";
                    break;
                case DownloadManager.PAUSED_WAITING_TO_RETRY:
                    reasonText = "PAUSED_WAITING_TO_RETRY";
                    break;
            }
            break;
        }
    }
    return reasonText;
}
 
Example 9
Source File: DownloadInfo.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
@StringRes
public static int getReasonTextResId(int status, int reason) {
    int reasonText = R.string.unKnown_status;
    switch (status) {
        case DownloadManager.STATUS_FAILED:
            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:
                    reasonText = (R.string.ERROR_UNKNOWN);
                    break;
            }
            break;
        case DownloadManager.STATUS_PAUSED: {
            switch (reason) {
                case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
                    reasonText = (R.string.PAUSED_QUEUED_FOR_WIFI);
                    break;
                case DownloadManager.PAUSED_UNKNOWN:
                    reasonText = (R.string.PAUSED_UNKNOWN);
                    break;
                case DownloadManager.PAUSED_WAITING_FOR_NETWORK:
                    reasonText = (R.string.PAUSED_WAITING_FOR_NETWORK);
                    break;
                case DownloadManager.PAUSED_WAITING_TO_RETRY:
                    reasonText = (R.string.PAUSED_WAITING_TO_RETRY);
                    break;
            }
            break;
        }
    }
    return reasonText;
}
 
Example 10
Source File: GeoPackageDownloadManager.java    From mage-android with Apache License 2.0 4 votes vote down vote up
private String getDownloadFailureStatus(Cursor cursor) {
    String status = null;

    if (cursor.moveToFirst()) {
        int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
        if(columnIndex != -1) {
            int reason = cursor.getInt(columnIndex);

            switch (reason) {
                case DownloadManager.ERROR_CANNOT_RESUME:
                    status = "Cannot Resume";
                    break;
                case DownloadManager.ERROR_DEVICE_NOT_FOUND:
                    status = "Device Not Found";
                    break;
                case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
                    status = "File Already Exists";
                    break;
                case DownloadManager.ERROR_FILE_ERROR:
                    status = "File Error";
                    break;
                case DownloadManager.ERROR_HTTP_DATA_ERROR:
                    status = "HTTP Data Error";
                    break;
                case DownloadManager.ERROR_INSUFFICIENT_SPACE:
                    status = "Insufficient Space";
                    break;
                case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
                    status = "Too Many Redirects";
                    break;
                case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
                    status = "Unhandled HTTP Code";
                    break;
                case DownloadManager.ERROR_UNKNOWN:
                default:
                    status = "Unknown Error";
                    break;
            }
        }
    }

    return status;
}
 
Example 11
Source File: BackgroundDownload.java    From cordova-plugin-background-download with Apache License 2.0 4 votes vote down vote up
private static String getUserFriendlyReason(int reason) {
    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;
        case HttpURLConnection.HTTP_BAD_REQUEST:
            failedReason = "BAD_REQUEST";
            break;
        case HttpURLConnection.HTTP_UNAUTHORIZED:
            failedReason = "UNAUTHORIZED";
            break;
        case HttpURLConnection.HTTP_FORBIDDEN:
            failedReason = "FORBIDDEN";
            break;
        case HttpURLConnection.HTTP_NOT_FOUND:
            failedReason = "NOT_FOUND";
            break;
        case HttpURLConnection.HTTP_INTERNAL_ERROR:
            failedReason = "INTERNAL_SERVER_ERROR";
            break;
        case ERROR_CANCELED:
            failedReason = "CANCELED";
            break;
    }

    return failedReason;
}