[Android Pro] to determine the URI corresponding to the contentprovider operation of the database U exist, and Downloadmanager pause, continue

Source: Internet
Author: User

Reference to:http://blog.csdn.net/u012858313/article/details/38821857

Project encountered a problem, is to use the Downloadmanager when the first judge, if you have their own definition of the use of their own, no words with the system,Downloadmanager code is actually written in the project, so at first not quite understand, and then think about, Originally refers to the Downloadmanager inside the database Downloadprovider, because Downloadprovider is not in my project manifest file, but in the company's mobile phone has been defined earlier, and the system The Downloadprovider in Downloadmanager is not in my control,

1, know the Downloads.Impl.CONTENT_URI of their definition;

Private voidchoosedownloads () {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 the Downloadmanager,

2. Downloadmanager pause, uri uri=new  contentvalues ();
Values.put (Android.provider.Downloads.COLUMN_CONTROL, Android.provider.Downloads.Impl.CONTROL_PAUSED);
NULL null);

3.DownloadManager continue (Must change Downloadmanager source, because the system Downloadmanager will not ignore you to android/android-downloadmanager-pro/

Uri uri=new  contentvalues (); if (Pausedforwifi) {    values.put (Android.provider.Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, Android.app.DownloadManager.Request.NETWORK_WIFI
| nullnull);

4. Start again:

systemanager.restartdownload (Downloadid); Uri uri=newnullnull);

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 ()) {intControl=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;

[Android Pro] to determine the URI corresponding to the contentprovider operation of the database U exist, and Downloadmanager pause, continue

Related Article

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.