Tool Class Summary---(vii) General tools for---

Source: Internet
Author: User

The so-called generic tool is a method that is often used, such as judging the state of the network, determining whether the SD exists, popping toasts, and so on.

 Packagecgjr.com.cgjr.utils;ImportAndroid.content.Context;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;Importandroid.os.Environment;Importandroid.text.TextUtils;ImportAndroid.util.Log;ImportAndroid.widget.Toast;Importorg.json.JSONException;ImportOrg.json.JSONObject;ImportJava.io.PrintWriter;ImportJava.io.StringWriter;ImportJava.io.Writer;Importcgjr.com.cgjr.CGApplication;ImportCGJR.COM.CGJR.DATA.ERRORMSG;/*** Created by Administrator on 2016/4/13.*/ Public classUtilityutils {/*** Determine if there is an Internet connection * *@paramContext *@return     */     Public Static Booleanisnewworkconnected (Context context) {if(Context! =NULL) {Connectivitymanager Mconnectivitymanager=(Connectivitymanager) Context.getsystemservice (Context.connectivity_service); if(Mconnectivitymanager! =NULL) {Networkinfo mobileinfo=Mconnectivitymanager.getnetworkinfo (Connectivitymanager.type_mobile); Networkinfo Wifiinfo=Mconnectivitymanager.getnetworkinfo (Connectivitymanager.type_wifi); if(Mobileinfo = =NULL|| !mobileinfo.isavailable ()) && (Wifiinfo = =NULL|| !wifiinfo.isavailable ())) {                    return false; }            } Else {                return false; }        }        return true; }     Public Static voidMaketext_short (context context, String msg) {if(! Textutils.isempty (MSG) && Context! =NULL) {Toast.maketext (Context, Textutils.isempty (msg)? "": Msg, Toast.length_long). Show (); }    }    /**     * @paramActivity Support Page *@paramobj parses the data image and resolves it to a JSON object for parsing operations *@return     * @throwsjsonexception*/     Public StaticJsonobject Parseobj (Context activity, Object obj)throwsjsonexception {return NewJsonobject (obj.tostring ()); }    /*** Determine if the SD card exists * *@return     */     Public Static Booleanishavesd () {if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {return true; } Else {            return false; }    }    /*** Save the error message to the local database * *@paramerrormsg Error message*/     Public Static voidSaveexceptioninfo (Throwable errormsg) {logutils.i ("Saveexceptioninfo", "Save error log:" +GetErrorInfo (errormsg)); ErrorMsg Error=Newerrormsg (Cgapplication.getapp (), GetErrorInfo (errormsg), log.error);    Error.save (); }    /*** GET error message * *@paramArg1 *@return     */     Public StaticString GetErrorInfo (Throwable arg1) {writer writer=NewStringWriter (); PrintWriter PW=NewPrintWriter (writer);        Arg1.printstacktrace (PW);        Pw.close (); String Error=writer.tostring (); returnerror; }}

The previous save error log to the local database is related to the problem of manipulating the local database.

 PackageCgjr.com.cgjr.data;ImportAndroid.os.Build;ImportAndroid.util.Log;ImportOrg.litepal.crud.DataSupport;Importjava.util.Date;Importcgjr.com.cgjr.CGApplication;Importcgjr.com.cgjr.constants.Constants;ImportCgjr.com.cgjr.utils.DateUtil;/*** Program Error class * Created by Administrator on 2016/4/13.*/ Public classErrorMsgextends datasupport { Publicerrormsg () {} Publicerrormsg (cgapplication cgapp) {setnet (Cgapp.getnetworkstatus ());    SetuId (Cgapp.getuserid ()); }     PublicErrorMsg (cgapplication Cgapp, String msg,intlog)        {setnet (Cgapp.getnetworkstatus ());        SetuId (Cgapp.getuserid ());        Setmsg (msg);    Setlog (log); }    /*** Priority Log level*/    Private intLog =Log.info; /*** User ID*/    PrivateString uId; /*** NETSTATUS;//network available status, 0 means no network available, 1 means WiFi network available 2 indicates that the cellular network is available*/    Private intNET = 0; /*** Phone Model*/    PrivateString MT =Build.model; /*** System version number*/    PrivateString SV =Build.VERSION.RELEASE; /*** OS*/    PrivateString os = "Android"; /*** App version*/    PrivateString av =Constants.version_; /*** Time*/    PrivateString time = dateutil.formatdatetostring (NewDate (), Dateutil.iso8601_datetime_pattern); /*** ERROR Content*/    PrivateString msg;  Public intGetLog () {returnlog; }     Public voidSetlog (intlog) {         This. log =log; }     PublicString Getuid () {returnuId; }     Public voidsetuId (String uId) { This. UId =uId; }     Public intgetnet () {returnnet; }     Public voidSetnet (intnet) {         This. NET =net; }     PublicString getmt () {returnMT; }     Public voidsetmt (String mt) { This. MT =MT; }     PublicString getsv () {returnSV; }     Public voidSETSV (String sv) { This. SV =SV; }     PublicString Getos () {returnOS; }     Public voidSetos (String os) { This. OS =OS; }     PublicString Getav () {returnav; }     Public voidsetav (String av) { This. av =av; }     PublicString GetTime () {returnTime ; }     Public voidsettime (String time) { This. Time =Time ; }     PublicString getmsg () {returnmsg; }     Public voidsetmsg (String msg) { This. msg =msg; }}

Tool Class Summary---(vii) General tools for---

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.