詳解 AndroidUtilCode 工具類庫

一、介紹

AndroidUtilCode 是一款收錄了大量常用工具類的 Android 庫,全稱為 Android Util Code,是 Android 平台上的工具類庫。這個庫里包含了 Android 開發過程中經常使用的工具方法,從開發效率、代碼重用性、代碼可讀性等方面都具有很大的幫助。另外,AndroidUtilCode 最獨到的就是將多種功能進行了封裝,對 Android 開發中使用頻率十分高的工具類做了很好的整合。

二、功能介紹

AndroidUtilCode 涵蓋的功能之多且發雜,無法完全列舉,主要包括Android框架相關、App相關、Bar相關、設備相關、Encode、File、Image、Keyboard、Lang、Log、Meta、Network、Permission、Reflect、Regex、Shell相關、Size、SPCache、Sub-process、Thread相關、Time、Toast、Zip等方面的功能。

1. Android框架相關

提供了對 Android 框架相關信息的獲取和使用,例如獲取 App 版本號、獲取設備 UID 等。

public static String getAppVersionName(Context context) // 獲取 App 版本號
public static int getAppVersionCode(Context context) // 獲取 App 版本碼
public static String getAndroidID() // 獲取 Android 設備唯一標識
public static String getMacAddress(Context context) // 獲取 Mac 地址
public static String getManufacturer() //獲取設備廠商
public static String getModel() // 獲取設備型號
public static String getDevice() //獲取設備名

2. App相關

提供了對 App 相關信息的獲取和使用,例如獲取當前 App 包名、安裝 App、App 啟動時間等。

public static void installApp(String filePath) // 安裝 App
public static boolean isAppInstalled(String packageName) // 判斷 App 是否已安裝
public static String getAppPackageName() // 獲取當前 App 包名
public static long getAppLastInstallTime(Context context) // 獲取 App 最後一次安裝時間
public static long getAppFirstInstallTime(Context context) // 獲取 App 第一次安裝時間
public static long getAppLastUpdateTime(Context context) // 獲取 App 最後一次更新時間
public static long getAppVersionCode(Context context) // 獲取 App 版本碼
public static String getAppVersionName(Context context) // 獲取 App 版本號
public static long getAppSize(Context context) // 獲取 App 安裝包大小
public static boolean isAppDebug() // 判斷 App 是否 Debug 版本
public static boolean isAppSystem() // 判斷 App 是否為系統應用
public static boolean isAppForeground() // 判斷 App 是否在前台
public static void relaunchApp() // 重啟 App
public static void exitApp() // 退出 App
public static void shareText(String text, String title) // 分享文本
public static void shareImage(String filePath, String title) // 分享圖片
public static void shareVideo(String filePath, String title) // 分享視頻
public static void shareAudio(String filePath, String title) // 分享音頻
public static void shareFile(String filePath, String title) // 分享文件

3. Bar相關

提供了對 Bar 相關信息的獲取和使用,例如設置狀態欄顏色和透明度。

public static void setStatusBarColor(Activity activity, int color) // 設置狀態欄顏色
public static void setStatusBarColor(Activity activity, int color, boolean isDecor) //設置狀態欄顏色,使用時不會影響其他 View 的布局
public static void setStatusBarAlpha(Activity activity, int alpha) // 設置狀態欄透明度
public static void setStatusBarAlpha(Activity activity, int alpha, boolean isDecor) // 設置狀態欄透明度,使用時不會影響其他 View 的布局
public static void setStatusBarColor4Drawer(Activity activity, DrawerLayout drawer, Toolbar toolbar, int color) // 為 DrawerLayout 設置狀態欄顏色
public static void setStatusBarAlpha4Drawer(Activity activity, DrawerLayout drawer, Toolbar toolbar, int alpha) // 為 DrawerLayout 設置狀態欄透明度

4. 設備相關

提供了對設備相關信息的獲取和使用,例如獲取設備屏幕信息、獲取設備生產商、獲取設備型號、獲取設備寬高、獲取設備序列號等。

public static boolean isDeviceRooted() // 判斷設備是否有 ROOT 權限
public static String getSDKVersionName() // 獲取 Android SDK 版本號
public static int getSDKVersionCode() // 獲取 Android SDK 版本碼
public static int getMinSdkVersion(Context context) // 獲取 App 最低版本號
public static int getMaxSdkVersion(Context context) // 獲取 App 最高版本號
public static String getSDKVersion() // 獲取 Android SDK 版本
public static String getFingerprint() // 獲取設備指紋信息
public static String getBoard() // 獲取設備主板信息
public static String getBootLoader() // 獲取設備引導程序版本號
public static String getBrand() // 獲取設備品牌信息
public static String getDevice() // 獲取設備型號信息
public static String getDisplay() // 獲取設備顯示信息
public static String getHardware() // 獲取設備硬件信息
public static String getManufacturer() // 獲取設備製造商信息
public static String getModel() // 獲取手機型號信息
public static String getProduct() // 獲取設備驅動信息
public static String getSerial() // 獲取設備序列號(該序列號不同於 AndroidId)
public static String getAndroidId() // 獲取 AndroidId
public static String getMacAddress() // 獲取 Mac 地址
public static String getIPAddress(boolean useIPv4) // 獲取 IP 地址
public static String getIMEI(Context context) // 獲取設備 IMEI 碼
public static String getIMSI(Context context) // 獲取設備 IMSI 碼
public static String getPhoneNumber(Context context) // 獲取設備手機號
public static int getScreenDensity() // 獲取設備屏幕密度(DPI)
public static float getScreenDensityScale() // 獲取設備屏幕密度比率
public static float getScreenScale() // 獲取設備屏幕比例
public static int getScreenWidth() // 獲取設備屏幕寬度
public static int getScreenHeight() // 獲取設備屏幕高度

5. Encode

提供了對編碼相關信息的獲取和使用,例如 MD5 加密、Base64 編碼解碼等。

public static byte[] hexString2Bytes(String hexString) // 十六進制字符串轉為 byte 數組
public static String bytes2HexString(byte[] bytes) // byte 數組轉為十六進制字符串
public static String bytes2Base64(byte[] bytes) // byte 數組轉為 Base64 編碼字符串
public static byte[] base642Bytes(String base64) // Base64 編碼字符串轉為 byte 數組(可以用於圖片Base64編碼)
public static String encodeMD2ToString(String data) // MD2 加密字符串
public static String encodeMD5ToString(String data) // MD5 加密字符串
public static String encodeSHA1ToString(String data) // SHA1 加密字符串
public static String encodeSHA256ToString(String data) // SHA256 加密字符串
public static String encodeSHA512ToString(String data) // SHA512 加密字符串
public static String encodeHmacMD5ToString(String data, String key) // HmacMD5 加密字符串
public static String encodeHmacSHA1ToString(String data, String key) // HmacSHA1 加密字符串
public static String encodeHmacSHA256ToString(String data, String key) // HmacSHA256 加密字符串
public static String encodeHmacSHA512ToString(String data, String key) // HmacSHA512 加密字符串

6. File

提供了對文件讀取和寫入、文件操作的封裝,例如獲取文件後綴名、獲取文件大小、比較文件內容是否一致等。

public static boolean isFileExists(String filePath) // 判斷文件是否存在
public static boolean writeFileFromString(String filePath, String content, boolean append) // 將字符串寫入文件
public static byte[] readFile2Bytes(String filePath) // 讀取指定文件內的 byte 數組
public static String readFile2String(String filePath) // 讀取指定文件內的字符串
public static boolean isFileEquals(File file1, File file2) // 判斷兩個文件是否相等
public static boolean isFileEquals(String filePath1, String filePath2) // 判斷兩個文件是否相等
public static boolean copyFile(String sourceFilePath, String destFilePath) // 將原文件複製到目標文件
public static boolean copyDir(String sourceDirPath, String destDirPath) // 將原文件夾複製到目標文件夾
public static boolean moveFile(String sourceFilePath, String destFilePath) // 將原文件移動到目標文件
public static boolean moveDir(String sourceDirPath, String destDirPath) // 將原文件夾移動到目標文件夾
public static boolean deleteFile(String filePath) // 刪除文件
public static boolean deleteDir(String dirPath) // 刪除文件夾
public static long getFileSize(String filePath) // 獲取文件大小
public static long getDirSize(String dirPath) // 獲取文件夾大小
public static String[] getDirName(String dirPath) // 獲取文件夾名稱
public static String[] getDirFiles(String dirPath) // 獲取文件夾內的文件名數組
public static String[] getDirPaths(String dirPath) // 獲取文件夾內的文件路徑數組
public static String getFileName(String filePath) // 獲取文件名
public static String getFileNameWithSuffix(String filePath) // 獲取文件名(帶後綴)
public static String getFileSuffix(String filePath) // 獲取文件後綴名
public static String getDirName(String filePath) // 獲取文件所在文件夾的名稱
public static String getAbsolutePath(File file) // 獲取文件絕對路徑

7. Image

提供了對圖片處理的封裝,例如圖片壓縮、圖片轉換等。

public static boolean save(Bitmap src, String filePath, Bitmap.CompressFormat format, boolean recycle) // 保存圖片
public static Bitmap compressByScale(Bitmap src, float scale, float quality, Bitmap.Config config, boolean recycle) // 按比例縮小圖片尺寸
public static Bitmap compressByScale(Bitmap src, float scale, Bitmap.Config config, boolean recycle) // 按比例縮小圖片尺寸
public static Bitmap compressByQuality(Bitmap src, int quality, Bitmap.Config config, boolean recycle) // 按質量壓縮圖片
public static Bitmap compressBySampleSize(Bitmap src, int sampleSize, Bitmap.Config config, boolean recycle) // 按採樣率縮小圖片尺寸
public static Bitmap rotate(Bitmap src, int degrees, float px, float py, boolean recycle) // 旋轉圖片
public static Bitmap rotate(Bitmap src, int degrees, boolean recycle) // 旋轉圖片
public static Bitmap toBitmap(Drawable drawable, int width, int height, Bitmap.Config config) // Drawable 轉為 Bitmap
public static byte[] bitmap2Bytes(Bitmap src, Bitmap.CompressFormat format) // Bitmap 轉為 byte 數組
public static Bitmap bytes2Bitmap(byte[] bytes) // Byte 數組轉為 Bitmap
public static Bitmap drawable2Bitmap(Drawable drawable) // Drawable 轉為 Bitmap
public static byte[] drawable2Bytes(Drawable drawable, Bitmap.CompressFormat format) // Drawable 轉為 byte 數組
public static Drawable bytes2Drawable(byte[] bytes) // Byte 數組轉為 Drawable
public static Drawable bitmap2Drawable(Bitmap bitmap) // Bitmap 轉為 Drawable
public static byte[] bitmap2Bytes(Bitmap bitmap) // Bitmap 轉為 byte 數組
public static Bitmap file2Bitmap(String filePath) // 文件轉為 Bitmap
public static Drawable file2Drawable(String filePath) // 文件轉為 Drawable
public static boolean save(Bitmap src, String filePath, Bitmap.CompressFormat format, boolean recycle) // 保存圖片
public static int getImageWidth(String filePath) // 獲取圖片寬度
public static int getImageHeight(String filePath) // 獲取圖片高度
public static String compressBySampleSize(String srcFilePath, String destFilePath, int inSampleSize) // 通過採樣率壓縮圖片
public static String compressByQuality(String srcFilePath, String destFilePath, int quality) // 通過質量壓縮圖片
public static String compressByScale(String srcFilePath, String destFilePath, float scale) // 通過縮放比例壓縮圖片
public static String compressByMaxSize(String srcFilePath, String destFilePath, int maxWidth, int maxHeight) // 通過最大寬高壓縮圖片
public static String compressByMinSize

原創文章,作者:VHFIE,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/369523.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
VHFIE的頭像VHFIE
上一篇 2025-04-13 11:45
下一篇 2025-04-13 11:45

相關推薦

  • Python字典去重複工具

    使用Python語言編寫字典去重複工具,可幫助用戶快速去重複。 一、字典去重複工具的需求 在使用Python編寫程序時,我們經常需要處理數據文件,其中包含了大量的重複數據。為了方便…

    編程 2025-04-29
  • 如何通過jstack工具列出假死的java進程

    假死的java進程是指在運行過程中出現了某些問題導致進程停止響應,此時無法通過正常的方式關閉或者重啟該進程。在這種情況下,我們可以藉助jstack工具來獲取該進程的進程號和線程號,…

    編程 2025-04-29
  • 註冊表取證工具有哪些

    註冊表取證是數字取證的重要分支,主要是獲取計算機系統中的註冊表信息,進而分析痕迹,獲取重要證據。本文將以註冊表取證工具為中心,從多個方面進行詳細闡述。 一、註冊表取證工具概述 註冊…

    編程 2025-04-29
  • Python運維工具用法介紹

    本文將從多個方面介紹Python在運維工具中的應用,包括但不限於日誌分析、自動化測試、批量處理、監控等方面的內容,希望能對Python運維工具的使用有所幫助。 一、日誌分析 在運維…

    編程 2025-04-28
  • t3.js:一個全能的JavaScript動態文本替換工具

    t3.js是一個非常流行的JavaScript動態文本替換工具,它是一個輕量級庫,能夠很容易地實現文本內容的遞增、遞減、替換、切換以及其他各種操作。在本文中,我們將從多個方面探討t…

    編程 2025-04-28
  • Trocket:打造高效可靠的遠程控制工具

    如何使用trocket打造高效可靠的遠程控制工具?本文將從以下幾個方面進行詳細的闡述。 一、安裝和使用trocket trocket是一個基於Python實現的遠程控制工具,使用時…

    編程 2025-04-28
  • gfwsq9ugn:全能編程開發工程師的必備工具

    gfwsq9ugn是一個強大的編程工具,它為全能編程開發工程師提供了一系列重要的功能和特點,下面我們將從多個方面對gfwsq9ugn進行詳細的闡述。 一、快速編寫代碼 gfwsq9…

    編程 2025-04-28
  • Python 編寫密碼安全檢查工具

    本文將介紹如何使用 Python 編寫一個能夠檢查用戶輸入密碼安全強度的工具。 一、安全強度的定義 在實現安全檢查之前,首先需要明確什麼是密碼的安全強度。密碼的安全強度通常包括以下…

    編程 2025-04-27
  • Morphis: 更加簡便、靈活的自然語言處理工具

    本文將會從以下幾個方面對Morphis進行詳細的闡述: 一、Morphis是什麼 Morphis是一個開源的Python自然語言處理庫,用於處理中心語言(目前僅支持英文)中的詞性標…

    編程 2025-04-27
  • HR測試用例生成工具:hrtest的全面解析

    本文將從使用、功能、優點和代碼示例等多個方面詳細介紹HR測試用例生成工具hrtest。 一、使用 HR測試用例生成工具hrtest是一款可以自動生成測試用例的工具,省去了繁瑣的手動…

    編程 2025-04-27

發表回復

登錄後才能評論