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))