Java Code Examples for android.app.DownloadManager#STATUS_FAILED
The following examples show how to use
android.app.DownloadManager#STATUS_FAILED .
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: MapDownloadUnzip.java From PocketMaps with MIT License | 7 votes |
/** Check first, if map is finished, or on pending status register receiver. **/ private static void broadcastReceiverCheck(Activity activity, final MyMap myMap, final StatusUpdate stUpdate, final long enqueueId) { int preStatus = getDownloadStatus(activity, enqueueId); if (preStatus == DownloadManager.STATUS_SUCCESSFUL) { stUpdate.logUserThread("Unzipping: " + myMap.getMapName()); unzipBg(activity, myMap, stUpdate); return; } else if (preStatus == DownloadManager.STATUS_FAILED) { DownloadMapActivity.clearDlFile(myMap); stUpdate.logUserThread("Error post-downloading map: " + myMap.getMapName()); } else { stUpdate.onRegisterBroadcastReceiver(activity, myMap, enqueueId); } }
Example 2
Source File: DownloadStorageProvider.java From FireFiles with Apache License 2.0 | 6 votes |
@SuppressLint("InlinedApi") private void includeDownloadFromCursor(MatrixCursor result, Cursor cursor) { final long id = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID)); final String docId = String.valueOf(id); final String displayName = cursor.getString( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE)); String summary = cursor.getString( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION)); String mimeType = cursor.getString( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE)); if (mimeType == null) { // Provide fake MIME type so it's openable mimeType = "vnd.android.document/file"; } Long size = cursor.getLong( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); if (size == -1) { size = null; } final int status = cursor.getInt( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS)); switch (status) { case DownloadManager.STATUS_SUCCESSFUL: break; case DownloadManager.STATUS_PAUSED: summary = getContext().getString(R.string.download_queued); break; case DownloadManager.STATUS_PENDING: summary = getContext().getString(R.string.download_queued); break; case DownloadManager.STATUS_RUNNING: final long progress = cursor.getLong(cursor.getColumnIndexOrThrow( DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); if (size != null) { final long percent = progress * 100 / size; summary = getContext().getString(R.string.download_running_percent, percent); } else { summary = getContext().getString(R.string.download_running); } break; case DownloadManager.STATUS_FAILED: default: summary = getContext().getString(R.string.download_error); break; } int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE; if (mimeType != null && mimeType.startsWith("image/")) { flags |= Document.FLAG_SUPPORTS_THUMBNAIL; } final long lastModified = cursor.getLong( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP)); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, docId); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_FLAGS, flags); }
Example 3
Source File: DownloadManagerService.java From delion with Apache License 2.0 | 6 votes |
@Override protected void onPostExecute(Pair<Integer, Boolean> result) { long downloadId = mDownloadItem.getSystemDownloadId(); if (result.first == DownloadManager.STATUS_SUCCESSFUL) { mOMADownloadHandler.onDownloadCompleted( mDownloadInfo, downloadId, mInstallNotifyURI); removeOMADownloadFromSharedPrefs(downloadId); mDownloadSnackbarController.onDownloadSucceeded( mDownloadInfo, DownloadSnackbarController.INVALID_NOTIFICATION_ID, downloadId, result.second); } else if (result.first == DownloadManager.STATUS_FAILED) { mOMADownloadHandler.onDownloadFailed( mDownloadInfo, downloadId, mFailureReason, mInstallNotifyURI); removeOMADownloadFromSharedPrefs(downloadId); String fileName = mDownloadInfo.getFileName(); onDownloadFailed(fileName, mFailureReason); } }
Example 4
Source File: UpdataReceiver.java From WanAndroid with Apache License 2.0 | 6 votes |
/** * 查询下载完成文件的状态 */ private void checkDownloadStatus(Context context, long downloadId) { mManager = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); Cursor cursor = mManager.query(query); if (cursor.moveToFirst()) { int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); switch (status) { case DownloadManager.STATUS_SUCCESSFUL: LogUtil.d(LogUtil.TAG_COMMON, "下载完成!"); RxBus.getInstance().post(new InstallApkEvent()); break; case DownloadManager.STATUS_FAILED://下载失败 ToastUtil.toastInBottom(context, context.getString(R.string.download_fail)); RxBus.getInstance().post(new OpenBrowseEvent()); LogUtil.d(LogUtil.TAG_COMMON, "下载失败....."); break; case DownloadManager.STATUS_RUNNING://正在下载 LogUtil.d(LogUtil.TAG_COMMON, "正在下载....."); break; default: break; } } }
Example 5
Source File: UtilsLibrary.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id, 0); Cursor cursor = downloadManager.query(query); if(cursor.moveToFirst()) { int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON)); if(status == DownloadManager.STATUS_SUCCESSFUL) { // Si la descarga es correcta abrimos el archivo para instalarlo File file = new File(Uri.parse(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath()); OpenNewVersion(context, file); } else if(status == DownloadManager.STATUS_FAILED) { Utils.toast(context.getString(R.string.appupdater_download_filed) + reason, context, LENGTH_LONG); } } }
Example 6
Source File: ClipDownloadControllerImpl.java From arcusandroid with Apache License 2.0 | 5 votes |
protected boolean downloadInProgress() { long downloadId = getDownloadID(); if (downloadId == -1) { return false; } try { switch (getDownloadManagerStatus(downloadId)) { case DownloadManager.STATUS_FAILED: removeCurrentDownloadReferences(); return false; case DownloadManager.STATUS_SUCCESSFUL: removeCurrentDownloadReferences(); return false; case DownloadManager.STATUS_PENDING: case DownloadManager.STATUS_PAUSED: case DownloadManager.STATUS_RUNNING: return true; default: case -1: return false; } } catch (Exception ex) { logger.error("Could not process download ID [{}]", downloadId, ex); } return false; }
Example 7
Source File: DownloadManagerService.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public Pair<Integer, Boolean> doInBackground(Void...voids) { DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = manager.query(new DownloadManager.Query().setFilterById( mDownloadItem.getSystemDownloadId())); int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int reasonIndex = c.getColumnIndex(DownloadManager.COLUMN_REASON); int titleIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE); int status = DownloadManager.STATUS_FAILED; Boolean canResolve = false; if (c.moveToNext()) { status = c.getInt(statusIndex); String title = c.getString(titleIndex); if (mDownloadInfo == null) { // Chrome has been killed, reconstruct a DownloadInfo. mDownloadInfo = new DownloadInfo.Builder() .setFileName(title) .setDescription(c.getString( c.getColumnIndex(DownloadManager.COLUMN_DESCRIPTION))) .setMimeType(c.getString( c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE))) .setContentLength(Long.parseLong(c.getString( c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)))) .build(); } if (status == DownloadManager.STATUS_SUCCESSFUL) { mDownloadInfo = DownloadInfo.Builder.fromDownloadInfo(mDownloadInfo) .setFileName(title) .build(); mDownloadItem.setDownloadInfo(mDownloadInfo); canResolve = canResolveDownloadItem(mContext, mDownloadItem, false); } else if (status == DownloadManager.STATUS_FAILED) { mFailureReason = c.getInt(reasonIndex); manager.remove(mDownloadItem.getSystemDownloadId()); } } c.close(); return Pair.create(status, canResolve); }
Example 8
Source File: Downloader.java From OpenHub with GNU General Public License v3.0 | 5 votes |
private void checkStatus() { //cause SQLiteException at 乐视 LE X820 Android 6.0.1,level 23 try{ DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); Cursor c = downloadManager.query(query); if (c.moveToFirst()) { int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); switch (status) { case DownloadManager.STATUS_PAUSED: break; case DownloadManager.STATUS_PENDING: break; case DownloadManager.STATUS_RUNNING: break; case DownloadManager.STATUS_SUCCESSFUL: String tip = mContext.getString(R.string.download_complete) .concat("\n").concat(getFilePath()); Toasty.success(mContext, tip).show(); unregister(); break; case DownloadManager.STATUS_FAILED: Toasty.error(mContext, mContext.getString(R.string.download_failed)).show(); unregister(); break; } } c.close(); }catch (SQLiteException e){ Logger.d(e); unregister(); } }
Example 9
Source File: UpdateHandler.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
/** * Retrieve information about a specific download from DownloadManager. */ private static CompletedDownloadInfo getCompletedDownloadInfo( final DownloadManagerWrapper manager, final long downloadId) { final Query query = new Query().setFilterById(downloadId); final Cursor cursor = manager.query(query); if (null == cursor) { return new CompletedDownloadInfo(null, downloadId, DownloadManager.STATUS_FAILED); } try { final String uri; final int status; if (cursor.moveToNext()) { final int columnStatus = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); final int columnError = cursor.getColumnIndex(DownloadManager.COLUMN_REASON); final int columnUri = cursor.getColumnIndex(DownloadManager.COLUMN_URI); final int error = cursor.getInt(columnError); status = cursor.getInt(columnStatus); final String uriWithAnchor = cursor.getString(columnUri); int anchorIndex = uriWithAnchor.indexOf('#'); if (anchorIndex != -1) { uri = uriWithAnchor.substring(0, anchorIndex); } else { uri = uriWithAnchor; } if (DownloadManager.STATUS_SUCCESSFUL != status) { Log.e(TAG, "Permanent failure of download " + downloadId + " with error code: " + error); } } else { uri = null; status = DownloadManager.STATUS_FAILED; } return new CompletedDownloadInfo(uri, downloadId, status); } finally { cursor.close(); } }
Example 10
Source File: AndroidDownloaderExecutor.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
@DownloadTask.DownloadResultRule private int getDownloadResult(@NonNull Cursor cursor) { switch (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) { case DownloadManager.STATUS_SUCCESSFUL: return DownloadTask.RESULT_SUCCEED; case DownloadManager.STATUS_FAILED: case DownloadManager.STATUS_PAUSED: return DownloadTask.RESULT_FAILED; default: return DownloadTask.RESULT_DOWNLOADING; } }
Example 11
Source File: UpdateHandler.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
/** * Retrieve information about a specific download from DownloadManager. */ private static CompletedDownloadInfo getCompletedDownloadInfo( final DownloadManagerWrapper manager, final long downloadId) { final Query query = new Query().setFilterById(downloadId); final Cursor cursor = manager.query(query); if (null == cursor) { return new CompletedDownloadInfo(null, downloadId, DownloadManager.STATUS_FAILED); } try { final String uri; final int status; if (cursor.moveToNext()) { final int columnStatus = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); final int columnError = cursor.getColumnIndex(DownloadManager.COLUMN_REASON); final int columnUri = cursor.getColumnIndex(DownloadManager.COLUMN_URI); final int error = cursor.getInt(columnError); status = cursor.getInt(columnStatus); final String uriWithAnchor = cursor.getString(columnUri); int anchorIndex = uriWithAnchor.indexOf('#'); if (anchorIndex != -1) { uri = uriWithAnchor.substring(0, anchorIndex); } else { uri = uriWithAnchor; } if (DownloadManager.STATUS_SUCCESSFUL != status) { Log.e(TAG, "Permanent failure of download " + downloadId + " with error code: " + error); } } else { uri = null; status = DownloadManager.STATUS_FAILED; } return new CompletedDownloadInfo(uri, downloadId, status); } finally { cursor.close(); } }
Example 12
Source File: ClipDownloadControllerImpl.java From arcusandroid with Apache License 2.0 | 5 votes |
protected void doGetStatus(long downloadId) { try { switch (getDownloadManagerStatus(downloadId)) { case DownloadManager.STATUS_FAILED: onDownloadComplete(getRecordingID(), STATUS_DOWNLOAD_CANCELED); removeCurrentDownloadReferences(); break; case DownloadManager.STATUS_SUCCESSFUL: onDownloadComplete(getRecordingID(), STATUS_DOWNLOAD_COMPLETE); removeCurrentDownloadReferences(); break; case DownloadManager.STATUS_PENDING: case DownloadManager.STATUS_PAUSED: case DownloadManager.STATUS_RUNNING: int progress = doGetDownloadProgress(); if (progress == 100) { onDownloadComplete(getRecordingID(), STATUS_DOWNLOAD_COMPLETE); removeCurrentDownloadReferences(); } else { onDownloadProgressChanged(progress, STATUS_DOWNLOAD_RUNNING); } break; } } catch (Exception ex) { removeCurrentDownloadReferences(); onDownloadFatalError(ex); } }
Example 13
Source File: Downloader.java From react-native-simple-download-manager with MIT License | 4 votes |
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 14
Source File: DownloadTreeViewAdapter.java From satstat with GNU General Public License v3.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { // this will be called when a download finishes Long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(reference); Cursor cursor = downloadManager.query(query); if (!cursor.moveToFirst()) { cursor.close(); return; } int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); //int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON)); cursor.close(); switch (status) { case DownloadManager.STATUS_SUCCESSFUL: // The file was downloaded successfully removeDownload(reference, true); break; case DownloadManager.STATUS_FAILED: // The download failed removeDownload(reference, false); break; case DownloadManager.STATUS_PAUSED: // The download was paused, update status once more checkProgress(); manager.refresh(); break; // The other status values are unusable because they don't fire reliably. } } else if (intent.getAction().equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { Intent mapDownloadIntent = new Intent(getActivity().getApplicationContext(), MapDownloadActivity.class); mapDownloadIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); if (savedInstanceState != null) mapDownloadIntent.putExtra(Const.KEY_SAVED_INSTANCE_STATE, savedInstanceState); getActivity().getApplicationContext().startActivity(mapDownloadIntent); } else if (intent.getAction().equals(Const.DOWNLOAD_RECEIVER_REGISTERED)) { /* * A new download receiver has been registered. If we're released, unregister. */ if (isReleased) getActivity().getApplicationContext().unregisterReceiver(downloadReceiver); } }
Example 15
Source File: DownloadInfo.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 4 votes |
@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 16
Source File: DownloadInfo.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 4 votes |
@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 17
Source File: DownloadMapActivity.java From PocketMaps with MIT License | 4 votes |
private static BroadcastReceiver createBroadcastReceiver(final Activity activity, final StatusUpdate stUpdate, final MyMap myMap, final long enqueueId) { log("Register receiver for map: " + myMap.getMapName()); BroadcastReceiver receiver = new BroadcastReceiver() { boolean isActive = true; @Override public void onReceive(Context context, Intent intent) { if (!isActive) { return; } String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { int dlStatus = MapDownloadUnzip.getDownloadStatus(context, enqueueId); if (dlStatus == DownloadManager.STATUS_SUCCESSFUL) { MapDownloadUnzip.unzipBg(activity, myMap, stUpdate); isActive = false; } else if (dlStatus == -1) { // Aborted log("Break downloading map: " + myMap.getMapName()); myMap.setStatus(MyMap.DlStatus.On_server); clearDlFile(myMap); isActive = false; } else if (dlStatus == DownloadManager.STATUS_FAILED) { // Error log("Error downloading map: " + myMap.getMapName()); myMap.setStatus(MyMap.DlStatus.Error); clearDlFile(myMap); isActive = false; } stUpdate.updateMapStatus(myMap); } } }; return receiver; }
Example 18
Source File: Updater.java From AndroidUpdater with Apache License 2.0 | 4 votes |
public void download(UpdaterConfig updaterConfig) { if (!UpdaterUtils.checkDownloadState(updaterConfig.getContext())) { Toast.makeText(updaterConfig.getContext(), R.string.system_download_component_disable, Toast.LENGTH_SHORT).show(); UpdaterUtils.showDownloadSetting(updaterConfig.getContext()); return; } long downloadId = UpdaterUtils.getLocalDownloadId(updaterConfig.getContext()); Logger.get().d("local download id is " + downloadId); if (downloadId != -1L) { FileDownloadManager fdm = FileDownloadManager.get(); //获取下载状态 int status = fdm.getDownloadStatus(updaterConfig.getContext(), downloadId); switch (status) { //下载成功 case DownloadManager.STATUS_SUCCESSFUL: Logger.get().d("downloadId=" + downloadId + " ,status = STATUS_SUCCESSFUL"); Uri uri = fdm.getDownloadUri(updaterConfig.getContext(), downloadId); if (uri != null) { //本地的版本大于当前程序的版本直接安装 if (UpdaterUtils.compare(updaterConfig.getContext(), uri)) { Logger.get().d("start install UI with local apk"); UpdaterUtils.startInstall(updaterConfig.getContext(), uri); return; } else { //从FileDownloadManager中移除这个任务 fdm.getDM(updaterConfig.getContext()).remove(downloadId); } } //重新下载 startDownload(updaterConfig); break; //下载失败 case DownloadManager.STATUS_FAILED: Logger.get().d("download failed " + downloadId); startDownload(updaterConfig); break; case DownloadManager.STATUS_RUNNING: Logger.get().d("downloadId=" + downloadId + " ,status = STATUS_RUNNING"); break; case DownloadManager.STATUS_PENDING: Logger.get().d("downloadId=" + downloadId + " ,status = STATUS_PENDING"); break; case DownloadManager.STATUS_PAUSED: Logger.get().d("downloadId=" + downloadId + " ,status = STATUS_PAUSED"); break; case STATUS_UN_FIND: Logger.get().d("downloadId=" + downloadId + " ,status = STATUS_UN_FIND"); startDownload(updaterConfig); break; default: Logger.get().d("downloadId=" + downloadId + " ,status = " + status); break; } } else { startDownload(updaterConfig); } }
Example 19
Source File: DownloadManagerDelegate.java From 365browser with Apache License 2.0 | 4 votes |
@Override public DownloadQueryResult doInBackground(Void... voids) { DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = manager.query( new DownloadManager.Query().setFilterById(mDownloadItem.getSystemDownloadId())); if (c == null) { return new DownloadQueryResult(mDownloadItem, DownloadManagerService.DOWNLOAD_STATUS_CANCELLED, 0, 0, false, 0); } long bytesDownloaded = 0; boolean canResolve = false; int downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_IN_PROGRESS; int failureReason = 0; long lastModifiedTime = 0; if (c.moveToNext()) { int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); if (status == DownloadManager.STATUS_SUCCESSFUL) { downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_COMPLETE; DownloadInfo.Builder builder = mDownloadItem.getDownloadInfo() == null ? new DownloadInfo.Builder() : DownloadInfo.Builder.fromDownloadInfo( mDownloadItem.getDownloadInfo()); builder.setFileName( c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE))); mDownloadItem.setDownloadInfo(builder.build()); if (mShowNotifications) { canResolve = DownloadManagerService.isOMADownloadDescription( mDownloadItem.getDownloadInfo()) || DownloadManagerService.canResolveDownloadItem( mContext, mDownloadItem, false); } } else if (status == DownloadManager.STATUS_FAILED) { downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_FAILED; failureReason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)); } lastModifiedTime = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP)); bytesDownloaded = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); } else { downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_CANCELLED; } c.close(); long totalTime = Math.max(0, lastModifiedTime - mDownloadItem.getStartTime()); return new DownloadQueryResult(mDownloadItem, downloadStatus, totalTime, bytesDownloaded, canResolve, failureReason); }
Example 20
Source File: UpdateService.java From Ency with Apache License 2.0 | 4 votes |
/** * 检查下载状态 */ private void checkStatus(Context context) { DownloadManager.Query query = new DownloadManager.Query(); //通过下载的id查找 query.setFilterById(downloadId); Cursor c = dm.query(query); if (c.moveToFirst()) { int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); switch (status) { //下载暂停 case DownloadManager.STATUS_PAUSED: break; //下载延迟 case DownloadManager.STATUS_PENDING: break; //正在下载 case DownloadManager.STATUS_RUNNING: break; //下载完成 case DownloadManager.STATUS_SUCCESSFUL: //下载完成安装APK File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "ency.apk"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Uri uri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider", file); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(uri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); } context.startActivity(intent); break; //下载失败 case DownloadManager.STATUS_FAILED: Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show(); break; } } c.close(); }