Small note: The initial package for the Android Web download tool! (including JSON, string download (volley), and picture Download (glide))

Source: Internet
Author: User

ImportAndroid.content.Context;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;ImportAndroid.widget.ImageView;ImportCom.android.volley.RequestQueue;ImportCom.android.volley.Response;ImportCom.android.volley.VolleyError;ImportCom.android.volley.toolbox.Volley;Importcom.bumptech.glide.Glide;ImportCom.bumptech.glide.load.engine.DiskCacheStrategy;ImportCOM.EXAMPLE.NR.CARTON.R;ImportDe.hdodenhof.circleimageview.CircleImageView;/*** Created by HJW on 2016/7/27.*/ Public classHttputils {/*** Verify that there is currently a network*/     Public Static Booleanchecknetwork (Context ct) {//Gets the connection management object--Connectivitymanager cm=(Connectivitymanager) Ct.getsystemservice (Context.connectivity_service); //Get Network Information objectsNetworkinfo ni=Cm.getactivenetworkinfo (); if(ni!=NULL&&ni.isavailable ())//non-null validation        {            return true; }        Else {            return false; }    }     Public  Static voidDownloadjson (Context context,string URL,Finalresultcallback CallBack) {Requestqueue Mqueue=volley.newrequestqueue (context); Mystringrequest stringrequest=Newmystringrequest (URL,NewResponse.listener<string>() {@Override Public voidOnresponse (String response) {if(response.tostring ()! =NULL) {callback.onsuccess (response.tostring ()); }                    }                }, NewResponse.errorlistener () {@Override Public voidonerrorresponse (volleyerror error) {}});    Mqueue.add (stringrequest); }     Public Static voiddownloadpic (String url,context context,imageview ImageView) {glide.with (Context). Load (URL) . Diskcachestrategy (Diskcachestrategy.all). Placeholder (R.drawable.bizhi). Error (    R.drawable.bizhi). Centercrop (). into (ImageView); }     Public Static voidDownLoadPic1 (String url,context context,imageview ImageView) {glide.with (Context). Load (URL) . Diskcachestrategy (Diskcachestrategy.all). Placeholder (R.drawable.bizhi). Error    (R.drawable.bizhi). into (ImageView); }     Public Static voiddownloadpiccircle (String url,context context,circleimageview imageView) {glide.with (Context). L Oad (URL). Diskcachestrategy (Diskcachestrategy.all)//. Placeholder (r.mipmap.ic_launcher)//. Error (R.mipmap.ic_launcher). Centercrop (). into (ImageView); }     Public Static voidDownloadpicresize (String url,context context,imageview ImageView,intWidthintheight)                {Glide.with (context). Load (URL). Diskcachestrategy (Diskcachestrategy.all) . Placeholder (R.drawable.bizhi). Error (R.drawable.bizhi). Centercrop (). O    Verride (width, height). into (ImageView); }    /*** When downloading asynchronously, save and transfer data via interface*/     Public Interfaceresultcallback{voidonsuccess (String s); //void OnError ();    }}

Small note: The initial package for the Android Web download tool! (including JSON, string download (volley), and picture Download (glide))

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.