详解 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/n/369523.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
VHFIEVHFIE
上一篇 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

发表回复

登录后才能评论