This article was originally written by Blankj. Reprinted by permission of The Activist Knight Brand Gallery.

README of English

API

  • The Activity related toActivityUtils.java-Demo

    IsActivityExists: Determines whether the Activity exists. Activity startActivity: Starts the Activity. GetLauncherActivity: Gets the entry. Get the top of the stack ActivityCopy the code
  • App related -AppUtils.java-Demo

    InstallApp: Installs the App (7.0 is supported) installAppSilent: silently installs the App uninstallApp: uninstalls the App uninstallAppSilent: checks whether the App is installed. LaunchApp: Open the App. GetAppPackageName: Obtain the App package name. GetAppDetailsSettings: GetAppName: Obtain the App name getAppIcon: obtain the App icon getAppPath: obtain the App path getAppVersionName: GetAppVersionCode: Obtain the App version isSystemApp: check whether the App is a system application isAppDebug: Check whether the App is the Debug version getAppSignature: GetAppSignatureSHA1: Obtain the SHA1 value of the App signature isAppForeground: Check whether the App is foreground getForegroundApp: Get the foreground application package name getAppInfo: GetAppsInfo: Obtains information about all installed apps. CleanAppData: clears all App dataCopy the code
  • Column related -BarUtils.java

    HideStatusBar: Hides the status bar getStatusBarHeight: obtains the status bar height isStatusBarExists Check whether the status bar exists. GetActionBarHeight: obtains the ActionBar height. ShowNotificationBar: displays the notification barCopy the code
  • Cache correlation →CacheUtils.java-Test

    GetBytes: reads a byte array from the cache. GetString: reads a String from the cache. GetJSONObject: JSONObject getJSONArray: JSONArray getBitmap: Bitmap getDrawable: Drawable getParcelable: Read Parcelable getSerializable from the cache: Read Serializable from the cache. GetCacheSize: Obtain the cache size. GetCacheCount: Obtain the cache number. Clear: Clears all cachesCopy the code
  • Clear correlation →CleanUtils.java-Demo

    CleanInternalCache: cleanInternalCache cleanInternalFiles: cleanInternalFiles cleanInternalDbs: clean internal database cleanInternalDbByName: CleanInternalSP: Clear internal SP cleanExternalCache: clear external cache cleanCustomCache: clear files in the customized directoryCopy the code
  • Clipboard related →ClipboardUtils.java

    CopyText: copyText to the clipboard getText: getText from the clipboard copyUri: copyUri to the clipboard getUri: get the uri from the clipboard copyIntent: copyIntent to the clipboard getIntent: get the intent from the clipboardCopy the code
  • Close correlation →CloseUtils.java

    CloseIO quietly: Quietly Close the I/OCopy the code
  • Transformation correlation →ConvertUtils.java-Test

    Bytes2HexString, hexString2Bytes: byteArr interconverts with hexString chars2Bytes, bytes2Chars: MemorySize2Byte, byte2MemorySize: indicates the memory size and the number of bytes in unit. [^ # ^ # ^ # ^ #] timespan: [^ # ^ # ^ # ^ # ^ #] [^ # ^ # ^ # ^ # ^ # ^ #]; Bytes2Bits, bits2Bytes: Bytes exchanged with bits input2OutputStream, output2InputStream: InputStream and outputStream interconvert inputStream2Bytes, bytes2InputStream: InputStream and byteArr interconvert outputStream2Bytes, bytes2OutputStream: InputStream2String, string2InputStream: InputStream interconverts with string encoding outputStream2String, string2OutputStream: Interconverts outputStream with string encoding bitmap2Bytes, bytes2Bitmap: Drawable2Bytes, bytes2Drawable: drawable2Bitmap: drawable2Bytes, bytes2Drawable: Drawable: view2Bitmap: view to Bitmap dp2px; px2dp: dp to sp2px; px2sp: sp to pxCopy the code
  • Crash correlation →CrashUtils.java

    GetInstance: obtains singleton init: initializes the singletonCopy the code
  • Device correlation →DeviceUtils.java-Demo

    IsDeviceRooted: checks whether the device is crinum. GetAndroidID: checks whether the device is crinum. GetManufacturer: obtain the device manufacturer getModel: obtain the device model Shutdown: shutdown reboot: restart reboot2Recovery: Restart to recovery reboot2Bootloader: Restart to bootloaderCopy the code
  • Short correlation →EmptyUtils.java-Test

    IsEmpty: checks whether the object isEmpty. IsNotEmpty: checks whether the object isNotEmptyCopy the code
  • Encoding decoding correlation →EncodeUtils.java-Test

    UrlEncode: URL encoding urlDecode: URL decoding base64Encode: base64Encode2String: Base64 encoding base64Decode: Base64 decoding base64UrlSafeEncode: Base64URL security encoding htmlEncode: Html encoding htmlDecode: Html decodingCopy the code
  • Encryption and decryption related →EncryptUtils.java-Test

    EncryptMD2, encryptMD2ToString: MD2 encryptMD5, encryptMD5ToString: MD5 encryptMD5File, encryptMD5File2String: EncryptSHA224 encryptSHA224ToString MD5 encryptSHA1, encryptSHA1ToString: SHA1 encryptSHA224, encryptSHA224ToString: EncryptSHA256, encryptSHA256ToString: SHA256 encryptSHA384, encryptSHA384ToString: SHA256 encryptSHA384, encryptSHA384ToString: EncryptSHA512, encryptSHA512ToString: encryptHmacMD5, encryptHmacMD5ToString: HmacMD5 encryption encryptHmacSHA1 encryptHmacSHA1ToString: HmacSHA1 encryption encryptHmacSHA224, encryptHmacSHA224ToString: HmacSHA224 encryption encryptHmacSHA256 encryptHmacSHA256ToString: HmacSHA256 encryption encryptHmacSHA384, encryptHmacSHA384ToString: HmacSHA384 encryption encryptHmacSHA512 encryptHmacSHA512ToString: HmacSHA512 encryptDES, encryptDES2HexString, encryptDES2Base64: DES EncryptDES decryptDES, decryptHexStringDES, decryptBase64DES: DES encrypt3DES, encrypt3DES2HexString, encrypt3DES2Base64: Decrypt3DES encryption decrypt3DES, decryptHexString3DES, decryptBase64_3DES: EncryptAES, encryptAES2HexString, encryptAES2Base64: AES encryptAES decryptAES, decryptHexStringAES, decryptBase64AES: AES decryptionCopy the code
  • File correlation →FileIOUtils.java-Test

    WriteFileFromBytesByStream writeFileFromIS: to write the input stream into the file: an array of bytes written to the file writeFileFromBytesByChannel: WriteFileFromBytesByMap: Writes a byte array to a file writeFileFromString: writes a string to a file readFile2List: ReadFile2String: Reads a file into a string readFile2BytesByStream: reads a file into a byte array readFile2BytesByChannel: ReadFile2BytesByMap: Reads a file into a byte arrayCopy the code
  • File correlation →FileUtils.java-Test

    IsFileExists: determines whether a file exists rename: renames a file isDir: determines whether a file exists isFile: determines whether a file exists createOrExistsDir: specifies whether a file exists. Whether directory exists, there is no judgment whether to create successful createOrExistsFile: to determine whether a file exists, does not exist, it determine whether create createFileByDeleteOldFile success: Check whether the file exists and delete the file before creating it. CopyDir: copy the directory. CopyFile: copy the file. Delete files. ListFilesInDir: Obtain all files in the directory. ListFilesInDir: Obtain all files in the directory, including subdirectories. Obtain all files with suffix suffix in the directory listFilesInDirWithFilter: Obtain all files with suffix suffix in the directory, including subdirectory listFilesInDirWithFilter: ListFilesInDirWithFilter: Obtains all filter-compliant files in the directory, including the subdirectory searchFileInDir: GetFileLastModified: getFileCharsetSimple: getFileCharsetSimple: getFileCharsetSimple: getFileLines: GetDirSize: obtain the directory size getFileSize: obtain the file size getDirLength: obtain the directory length getFileLength: obtain the file length getFileMD5: GetFileMD5ToString: obtains the MD5 verification code of the file getDirName: obtains the longest directory based on the full path getFileName: obtains the file name based on the full path getFileNameNoExtension: GetFileExtension: Obtain the extension name of the file based on the full pathCopy the code
  • Fragments related -FragmentUtils.java-Demo

    AddFragments: Add multiple fragments removeFragment: RemoveToFragment: Removes fragments from the specified fragment removeFragments: Removes fragments of the same level Remove all fragments replaceFragment: replace fragments popFragment: the stack fragments popToFragment: out of the stack to specify fragments popFragments: PopAddFragment: Removes all fragments at the same level popAllFragments: Removes all fragments at the same level popAddFragment: removes new fragments at the same level Hide the same level of fragment showFragment: Displays the fragment hideShowFragment: hides the fragment before displaying the fragment getLastAddFragment: Get with level eventually join the fragments of getLastAddFragmentInStack: obtain the stack with level eventually join the fragments of getTopShowFragment: To get the top visible fragments getTopShowFragmentInStack: gaining the top visible fragments in stack getFragments: access to the same level fragments getFragmentsInStack: Obtain all fragments in the stack. GetAllFragmentsInStack: Obtain all fragments in the stack. FindFragment: searches for the fragment dispatchBackPress: processes the fragment. SetBackgroundColor: SetBackgroundResource: Sets background resource setBackground: sets backgroundCopy the code
  • Handler associated -HandlerUtils.java-Demo

    HandlerHolder: Use required readingCopy the code
  • Pictures related →ImageUtils.java-Demo

    Bitmap2Bytes, bytes2Bitmap: drawable2Bitmap, bitmap2Drawable: Drawable: drawable: drawable: bytes2Drawable: Drawable: byteArr: drawable: Drawable: byteArr: drawable: getBitmap: obtain bitmap scale: scale the image clip: Skew: the image is rotated skew: the image is rotated getRotateDegree: the image is rotated toRound: the image is rounded toRoundCorner: the image is rounded fastBlur: the image is rotated How to add a color to the frame and add it to the addReflection AddImageWatermark: addImageWatermark toAlpha: convert toAlpha bitmap toGray: convert to grayscale image save: save the image isImage: Determine whether the file is a picture based on the file name. GetImageType: obtain the image type. CompressByScale: compress the file by scalingCopy the code
  • Intention correlation →IntentUtils.java

    GetInstallAppIntent: Obtains the intent to install the App (supports 6.0). Gettuninstallappintent: Obtains the intent to uninstall the App. GetLaunchAppIntent: For open the App intention getAppDetailsSettingsIntent: for specific Settings App intention getShareTextIntent: share access to the intention of the text getShareImageIntent: For share photos intention getComponentIntent: access to the intentions of other application components getShutdownIntent: get off the intention of the getCaptureIntent: access to the intention of the photoCopy the code
  • Keyboard related →KeyboardUtils.java-Demo

    HideSoftInput: dynamic hide the soft keyboard clickBlankArea2HideSoftInput: click on the blank area to hide the screen soft keyboard showSoftInput: dynamic display soft keyboard toggleSoftInput: switch the keyboard display or notCopy the code
  • Positioning correlation →LocationUtils.java-Demo

    IsGpsEnabled: checks whether Gps is available isLocationEnabled: checks whether Gps is available openGpsSettings: opens the Gps setting page register: registers unregister: GetCountryName: Obtain the locality based on the longitude and latitude getStreet: IsBetterLocation: is the better location isSameProvider: is the same providerCopy the code
  • Log correlation →LogUtils.java-Demo

    Builder.setLogSwitch: Set the log master switch builder. setConsoleSwitch: set the log console switch Builder.setGlobalTag: set the log console switch builder. setConsoleSwitch: Set the log console switch Builder.setGlobalTag: Set the log global tag Builder. SetLogHeadSwitch: set up the log header information switch Builder. SetLog2FileSwitch: set the log file switch Builder. SetDir: SetBorderSwitch: Set log border switch Builder.setConsolefilter: Set log console filter Builder.setFilefilter: Set the log file filter v: Verbose log D: Debug log I: Info log W: Warn log E: Error log A: Assert log file: log to a file json: Json XML for log strings: XML for log stringsCopy the code
  • Network correlation →NetworkUtils.java-Demo

    IsConnected: checks whether the network isConnected. IsAvailableByPing: checks whether the network is available. GetDataEnabled: Check whether mobile data is enabled setDataEnabled: enable or disable mobile data is4G: check whether the network is4G getWifiEnabled: check whether wifi is enabled setWifiEnabled: IsWifiConnected: Connected to a wifi interface isWifiAvailable: Connected to a wifi interface getNetworkOperatorName GetNetworkType: obtains the current network type. GetIPAddress: obtains the IP address. GetDomainAddress: obtains the IP address of the domain nameCopy the code
  • Mobile related →PhoneUtils.java-Demo

    GetIMEI: obtain the IMEI code. GetIMSI: obtain the IMSI code. GetPhoneType: obtain the mobile terminal type. GetSimOperatorName: obtains the operator name of the SIM card. GetSimOperatorByMnc: obtains the operator name of the SIM card. GetPhoneStatus: obtains the mobile phone status. Call: dial phoneNumber sendSms: jump to the page for sending SHORT messages sendSmsSilent: send short messages getAllContactInfo: obtain mobile phone contacts getContactNum: Tap a contact to obtain the phone number. GetAllSMS: Obtain a mobile phone short message and save it in XMLCopy the code
  • Pinyin related →PinyinUtils.java-Test

    Ccs2Pinyin: Chinese character to pinyin getPinyinFirstLetter: get the first letter of Chinese character getPinyinFirstLetter: GetSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetter getSurnameFirstLetterCopy the code
  • Process correlation →ProcessUtils.java-Demo

    GetForegroundProcessName: access to the foreground thread package name killAllBackgroundProcesses: kill all the backend service process killBackgroundProcesses: kill the background service processCopy the code
  • Canonical correlation →RegexUtils.java-Test

    IsMobileSimple: verify mobile phone number (simple) isMobileExact: verify mobile phone number (exact) isTel: verify phone number isIDCard15: verify ID card number 15-digit isIDCard18: verify mobile phone number Verify ID card number 18-bit isEmail: verify email address isURL: verify URL isZh: verify Chinese characters isUsername: verify user name isDate: verify date verification in YYYY-MM-DD format, with even leap year taken into account isIP: GetMatches: The portion of the matched regula ti on is obtained. Gettreplacefirst: The first part of the matched regula ti on is replaced. GetReplaceAll: Replace all portions of the re matchCopy the code
  • Screen correlation →ScreenUtils.java

    GetScreenWidth: Get the width of the screen (unit: px) getScreenHeight: Get the height of the screen (unit: px) IsLandscape: determine whether the screen isPortrait isPortrait: determine whether the screen isPortrait getScreenRotation: get the screen rotation Angle captureWithStatusBar: Obtain the current screen shot, including the status bar captureWithoutStatusBar: obtain the current screen shot, excluding the status bar isScreenLock: determine whether to lock the screenCopy the code
  • SD card related →SDCardUtils.java-Demo

    GetSDCardPath: path to obtain the SD card getDataPath: path to obtain the Data of the SD card getFreeSpace: calculates the remaining space of the SD card getSDCardInfo: Obtain SD card informationCopy the code
  • Service related →ServiceUtils.java

    StartService: starts a service. StopService: stops a service. BindService: binds a service. Unbinding service isServiceRunning: Checks whether the service is runningCopy the code
  • Shell related -ShellUtils.java

    ExecCmd: Indicates whether to run the command under rootCopy the code
  • Size correlation →SizeUtils.java

    Dp2px, px2dp: dp and px convert sp2px, px2sp: sp and px convert applyDimension: Measureviewmeasureviewmeasuredwidth getMeasuredHeight getMeasuredHeightCopy the code
  • Snackbar related -SnackbarUtils.java-Demo

    ShowShort: displays a short snackbar showLong: displays a long snackbar showIndefinite: displays a user-defined length snackbar addView: adds a layout to the snackbar. Dismiss: Cancel the snackbar displayCopy the code
  • SpannableString related -SpannableStringUtils.java-Demo

    Builder. SetFlag: set the logo Builder. SetForegroundColor: set your foreground color Builder. SetBackgroundColor: set the background color Builder. SetQuoteColor: SetLeadingMargin: Sets the indentation builder. setMargin: Sets the spacing builder. setBullet: Sets the list tag Builder.setFontSize: Set the font size Builder. SetFontProportion: set font proportion Builder. SetFontXProportion: set font transverse proportion Builder. SetStrikethrough: Builder.setUnderline: Builder.setSuperscript: Builder.setSubscript: Builder.setBold: builder. setUnderline: Builder.setUnderline: builder. setSuperscript: Builder.setSubscript: Builder.setBold: SetBoldItalic: setItalic builder. setFontFamily: set font series builder. setItalic: setItalic builder. setBoldItalic: setItalic builder. setFontFamily: set font series builder. setTypeface: SetBitmap: Set image Builder.setDrawable: Set image Builder.setUri: Set font builder. setAlign: Set alignment Builder.setBitmap: Set image Builder.setDrawable: Set image Builder.setUri: Set image Builder.setResourceId: Set image Builder.setClickSpan: Set click event Builder.setUrl: Set hyperlink Builder.setBlur: Set fuzzy Builder.append: Appends style string Builder.create: creates style stringCopy the code
  • SP related -SPUtils.java-Test

    GetString: read from SP. GetInt: read from SP. Int getLong: read from SP. Long getFloat: Boolean getAll: obtains all key-value pairs from SP contains: indicates whether the key exists in SP. Remove: indicates that the key is removed from SP. Clear: indicates that all data is cleared from SPCopy the code
  • String correlation →StringUtils.java-Test

    IsEmpty: checks whether the string is null or has a length of 0. IsTrimEmpty: checks whether the string is null or full of Spaces. IsSpace: checks whether the string is null or full of empty characters. EqualsIgnoreCase: determines whether two strings are equal. Null2Length0: null converts to a string of length 0. Length: Returns the length of the string upperFirstLetter: Uppercase lowerFirstLetter: lowercase letter Reverse: indicates that the character string is reversed toDBC: indicates that the character string is converted to a half-angle character toSBC: indicates that the character string is converted to a full-angle characterCopy the code
  • Thread pool related →ThreadPoolUtils.java

    ThreadPoolUtils: ThreadPoolUtils constructor execute: execute a given command at a future time execute a given list of commands at a future time shutDown: ShutDownNow: attempts to stop all active tasks in progress. IsShutDown: checks whether the thread pool is closed. IsTerminated: Submit: Submits a Callable task to execute submit: Submit a Runnable task to execute invokeAll, invokeAny: execute the given task schedule: Delay the execution of the Runnable command schedule: Delay executing the Callable command scheduleWithFixedRate: indicates that the Callable command is delayed and executed periodically. ScheduleWithFixedDelay: indicates that the Callable command is executed periodically at a fixed rest timeCopy the code
  • Time correlation →TimeUtils.java-Test

    String string2Millis millis2String: a timestamp to time: the time string to a timestamp string2Date: a time string to Date type date2String: Date2Millis [^ 5 ^ 5] date2Millis [^ 5 ^ 5] date2Millis [^ 5 ^ 5]. GetNowMills: Gets the current millisecond timestamp getNowString: Gets the current time string getNowDate: Gets the current Date getTimeSpanByNow: Get worse and the current time (unit: the unit) getFitTimeSpanByNow: get the right type and the current time difference getFriendlyTimeSpanByNow: get friendly with the current time bad getMillis: GetDate: getzipgebyNow (); getzipgebyNow (); String getDateByNow: getDateByNow: getdate isToday: checks whether today is the day isLeapYear: GetUSWeek: Obtain the American week getWeekIndex: obtain the week index getWeekOfMonth: obtain the week in a month getWeekOfYear: Get the week of the year getZodiac: Get the zodiacCopy the code
  • Toast related →ToastUtils.java-Demo

    SetGravity: set toast position setView: set the toast view getView: access to toast the view showShortSafe: safely shows short toast showLongSafe: safely shows long toast showShort: ShowLong: displays long toast cancel: cancels the toast displayCopy the code
  • Compression correlation →ZipUtils.java-Test

    ZipFiles: decompresses files in batches zipFile: decompresses files in batches unzipFile: decompresses files in batches unzipFileByKeyword: decompresses files with keywords getFilesPath: decompresses files with keywords GetComments: obtains the linked list of comments in the compressed file. GetEntries: obtains the file object in the compressed fileCopy the code
  • Update the Log -update_log.md


Download

Gradle:

The compile 'com. Blankj: utilcode: 1.6.3'Copy the code

How to use

// init it in the function of onCreate in ur Application
Utils.init(context);
Copy the code

Proguard

-keep class com.blankj.utilcode.** { *; }
-keepclassmembers class com.blankj.utilcode.** { *; }
-dontwarn com.blankj.utilcode.**
Copy the code

The author:Rance935Source:Code that Android developers have to collect (in constant update)Please indicate the author’s details and the source of this article at the beginning of the reprint

Welcome to follow my wechat official account and QQ group to share Android development and Internet content

Android technology share: group number 534813930

Wechat id: AndroidParks

Public id: AndroidParks