When DownloadManager is used, the DownloadManager code is written in the project. If DownloadManager is defined by itself and does not exist, the system code is used, so I didn't quite understand it at the beginning. I thought about it later. It originally referred to the database DownloadProvider in downloadmanager, because DownloadPro
When DownloadManager is used, the DownloadManager code is written in the project. If DownloadManager is defined by itself and does not exist, the system code is used, so I didn't quite understand it at the beginning. I thought about it later. It originally referred to the database DownloadProvider in downloadmanager, because DownloadPro
When DownloadManager is used, the DownloadManager code is written in the project. If DownloadManager is defined by itself and does not exist, the system code is used, I didn't quite understand it at the beginning. I thought about it later. It originally referred to the database DownloadProvider in downloadmanager, because DownloadProvider is not in the configuration file of my project, it has been defined in the company's mobile phone, and the DownloadProvider in the system's DownloadManager is not controlled by me,
1. Know your own Downloads. Impl. CONTENT_URI;
private void chooseDownloads() {Cursor cursor=mContext.getContentResolver().query(uri, null, null, null, null);if (cursor == null) {isSystemDownload = true;systeManager = (android.app.DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);} else {isSystemDownload = false;nonSystemManager = DownloadManager.getInstance(mContext);}}
2. Suspension of DownloadManager,
Uri uri=ContentUris.withAppendedId(android.provider.Downloads.Impl.CONTENT_URI, downloadId);ContentValues values = new ContentValues();values.put(android.provider.Downloads.COLUMN_CONTROL, android.provider.Downloads.Impl.CONTROL_PAUSED);values.put(android.provider.Downloads.Impl.COLUMN_STATUS, android.provider.Downloads.Impl.STATUS_PAUSED_BY_APP);mContext.getContentResolver().update(uri, values, null, null);
3. Continue DownloadManager (the downloadmanager source code must be changed, because the system's downloadmanager does not care about your operations on COLUMN_STATUS)
Downloadmanager source code modification reference http://www.trinea.cn/android/android-downloadmanager-pro/
Uri uri=ContentUris.withAppendedId(android.provider.Downloads.Impl.CONTENT_URI,downloadId);ContentValues values = new ContentValues();if (pausedForWifi) {values.put(android.provider.Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, android.app.DownloadManager.Request.NETWORK_WIFI | android.app.DownloadManager.Request.NETWORK_MOBILE);}values.put(android.provider.Downloads.Impl.COLUMN_CONTROL,android.provider.Downloads.Impl.CONTROL_RUN);values.put(android.provider.Downloads.Impl.COLUMN_STATUS, android.provider.Downloads.Impl.STATUS_RUNNING);mContext.getContentResolver().update(uri, values, null, null);
4. Start again:
systeManager.restartDownload(downloadId);Uri uri=ContentUris.withAppendedId(android.provider.Downloads.Impl.CONTENT_URI, downloadId);ContentValues values = new ContentValues();values.put(android.provider.Downloads.Impl.COLUMN_CONTROL, android.provider.Downloads.Impl.CONTROL_RUN);mContext.getContentResolver().update(uri, values, null, null);
5. Determine whether to manually control pause or run
Uri uri=ContentUris.withAppendedId(android.provider.Downloads.Impl.CONTENT_URI, downloadId);Cursor cursor = mContext.getContentResolver().query(uri, null, null,null, null);while (cursor.moveToNext()) {int control=cursor.getInt(cursor.getColumnIndex(android.provider.Downloads.Impl.COLUMN_CONTROL));if (android.provider.Downloads.Impl.CONTROL_RUN!=control&&android.provider.Downloads.Impl.CONTROL_PAUSED != control) {return true;}}return false;