Determine whether the database u operated by the ContentProvider corresponding to the Uri exists and DownloadMa

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.