AndroidUtilCode 🔥 is a powerful & easy to use library for Android

Overview

logo

frame

auc result build License

README of Chinese

About

AndroidUtilCode 🔥 is a powerful & easy to use library for Android. This library encapsulates the functions that commonly used in Android development which have complete demo and unit test. By using it's encapsulated APIs, you can greatly improve the development efficiency. The program mainly consists of two modules which is utilcode, which is commonly used in development, and subutil which is rarely used in development, but the utils can be beneficial to simplify the main module. 🔥

Documentation

utilcode

subutil

Donations

If this project helps you a lot and you want to support the project's development and maintenance of this project, feel free to scan the following QR code for donation. Your donation is highly appreciated. Thank you!

donate

Contact

Blog jianshu weibo QQGroup

Change Log

打个小广告

欢迎加入我的小专栏「基你太美」一起学习。

Issues
  • [BUG] 1.28.x 汇总

    [BUG] 1.28.x 汇总

    版本变更

    1.27.x 重构版本经过多次的 BUG 修复已趋于稳定,欢迎大家使用 1.28.x。

    BUG 描述模板

    拷贝如下模板到下方来提交 BUG

    ## 描述 Bug
    
    简洁地描述下 Bug。
    - AndroidUtilCode 的版本:例如 utilcode:1.28.0 或 utilcodex:1.28.0
    - 出现 Bug 的设备型号: 例如 Nexus 5X
    - 设备的 Android 版本:例如 API 27
    
    ## 相关代码
    
    ```
    put your code here
    ```
    
    ## 异常堆栈
    
    ```
    put the stack of crash here
    ```
    
    ## 截图
    
    如果有的话请添加屏幕截图以帮助解释问题。
    
    bug 
    opened by Blankj 50
  • 屏幕适配xdpi赋值没有成功

    屏幕适配xdpi赋值没有成功

    我的两个设备都是华为M2,一个是16g的一个是64g的。 在执行val dm = getDisplayMetrics(resources)这个代码之后我打印了dm。 16g的信息是DisplayMetrics:DisplayMetrics{density=1.5, width=1920, height=1200, scaledDensity=1.5, xdpi=108.0, ydpi=224.737},

    64g的信息是:DisplayMetrics:DisplayMetrics{density=1.5, width=1920, height=1128, scaledDensity=1.5, xdpi=225.777, ydpi=224.737}

    最后打印的val newXdpi = dm.xdpi这个值都是108.0到这是没有问题的。 等到控件绘制的时候我发现我的xdpi这个值在64g的设备中并没有赋值成功,打印的还是原始值 xdpi=225.777(如果赋值成功的话xdpi应该是108.0)

    下面附上效果: 这是64g的设备 Screenshot_2019-03-14-15-00-07

    Screenshot_2019-03-14-14-59-54

    Screenshot_2019-03-14-15-00-18 这个显然是不对的,但是我把这个设备的屏幕旋转为竖屏时好像是对的

    微信图片_20190314151623

    以下是16g的设备截图,是正常的 Screenshot_2019-03-14-15-01-01

    Screenshot_2019-03-14-15-00-55

    Screenshot_2019-03-14-15-00-41

    想问下这种情况应该是怎么回事?

    注:以上我说的16g和64g只是为了区分两个设备的不同

    opened by BeatGeneration 43
  • [BUG] 1.27.x 汇总

    [BUG] 1.27.x 汇总

    版本变更

    升级到 1.27.x 版本发生了重构,所带来的 bug 可能比较多,在此深表歉意,目前已修复差不多了 :-)

    • 最新版本:1.27.6
    • 1.27.0 版本变更详情: https://github.com/Blankj/AndroidUtilCode/releases/tag/1.27.0
    • 1.27.1:
      • 修复 ActivityUtils finish 堆栈不正确的 BUG
      • 修复 PathUtils 中判断 SD 卡状态反了的 BUG
    • 1.27.2:
      • 修复 UtilsActivityLifecycleImpl 的 HashMap#remove IllegalStateException Bug
      • 修复 ShadowUtils 阴影低版本问题
    • 1.27.3:
      • 修改 GsonUtils#getGson() 为 public
      • 修复 LogUtils 写入文件不起作用
      • 修复 CrashUtils 设置的 DefaultUncaughtExceptionHandler 导致的卡死现象
      • 修复 Utils#getApp 多进程获取为空的问题
    • 1.27.4
    • 1.27.5
      • 修复 ActivityUtils finish 不正确的 BUG
    • 1.27.6
      • 修复 FileUtils#isFileExists
      • 修复 FragmentUtils#getTop

    BUG 描述模板

    拷贝如下模板到下方来提交 BUG

    ## 描述 Bug
    
    简洁地描述下 Bug。
    - AndroidUtilCode 的版本:例如 utilcode:1.27.0 或 utilcodex:1.27.0
    - 出现 Bug 的设备型号: 例如 Nexus 5X
    - 设备的 Android 版本:例如 API 27
    
    ## 相关代码
    
    ```
    put your code here
    ```
    
    ## 异常堆栈
    
    ```
    put the stack of crash here
    ```
    
    ## 截图
    
    如果有的话请添加屏幕截图以帮助解释问题。
    
    bug 
    opened by Blankj 38
  •  AppUtils静默安装在8.1系统失败

    AppUtils静默安装在8.1系统失败

    测试5.1方法可用,8.1无法使用,commandResult错误信息是空指针

    opened by Reginer 36
  • Toastutil为什么要改样式?

    Toastutil为什么要改样式?

    建议不要修改ToastUtils默认样式。看着很别扭。

    opened by yuzhiqiang1993 30
  • ToastUtil 在华为平板7.0的系统上有问题,会引起其他控件的错误

    ToastUtil 在华为平板7.0的系统上有问题,会引起其他控件的错误

    2018-10-19 10:50:38.291 9028-9028/com.tendao.rushrepair E/InputEventReceiver: Exception dispatching input event. 2018-10-19 10:50:38.291 9028-9028/com.tendao.rushrepair E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 2018-10-19 10:50:38.296 9028-9028/com.tendao.rushrepair E/MessageQueue-JNI: android.content.res.Resources$NotFoundException: Drawable android:drawable/text_select_handle_middle_material with resource ID #0x1080761 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/text_select_handle_middle_material.xml from drawable resource ID #0x1080761 at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:935) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:769) at android.content.res.Resources.getDrawable(Resources.java:834) at android.content.Context.getDrawable(Context.java:529) at android.widget.Editor$InsertionPointCursorController.getHandle(Editor.java:5221) at android.widget.Editor$InsertionPointCursorController.show(Editor.java:5200) at android.widget.Editor.onTouchUpEvent(Editor.java:2196) at android.widget.TextView.onTouchEvent(TextView.java:8854) at android.view.View.dispatchTouchEvent(View.java:10013)

    opened by glmsb 23
  • 屏幕适配问题汇总及解决

    屏幕适配问题汇总及解决

    适配的原理及怎么适配?

    Android 屏幕适配从未如斯简单(8月10日最终更新版),由于文章写的较早,请用 1.19.2 版本及以上来完美适配。

    如何创建 mdpi 1080 * 1920 设备的预览图?

    创建新的模拟器设备,然后修改分辨率和屏幕尺寸使其达到 mdpi 即可。

    App 进入后台一段时间再进入导致适配失效?

    由于进入后台可能会触发 onDestroy,导致取消了适配,从而再次进入 App 的时候可能会出现适配失效。如果是所有页面都需要适配,那就不需要在 onDestroy 里做取消适配;如果某些页面不需要适配,那就在它 setContentView 之前取消适配即可。

    webview 加载后发现 density 复原?

    由于 WebView 初始化的时候会还原 density 的值导致适配失效,继承 WebView,重写如下方法:

    @Override
    public void setOverScrollMode(int mode) {
        super.setOverScrollMode(mode);
        ScreenUtils.restoreAdaptScreen();
    }
    

    如何让系统 View 尺寸正常?

    后面提到的 Dialog 和 Toast 其实都可以用用这种解决方案,就是在 inflate 相关 View 之前调用 ScreenUtils#cancelAdaptScreenshow 之后调用 ScreenUtils#restoreAdaptScreen 即可,这样就可以让系统 View 显示正常尺寸。

    显示 dialog 尺寸有问题?

    如果你适配传入的不是 mdpi 下的尺寸,而是 xxhdpi,那么可能会导致 AlertDialog 跑到屏幕外边,所以在文章中我也提到了只用 mdpi 来适配,正常情况的 mdpi 是会呈现比较小的尺寸,如果你要取得和原生一致的效果,那就利用上面提到的「如何让系统 View 尺寸正常」封装下在 Dialog 显示前调用 ScreenUtils#cancelAdaptScreen,Dismiss 后根据需求看是否需要 ScreenUtils#restoreAdaptScreen;或者你也可以给 Dialog 定制统一的 styles 来解决尺寸(<item name="android:windowMinWidthMinor">576dp</item> <!-- 占 80% 屏宽 720 * 0.8 = 576 -->)、字体的问题。当然,如果项目组有封装好的 Dialog,那么统一修改这个 Dialog 库的尺寸即可。

    Toast 尺寸有问题?

    使用 1.19.1 及以上版本的 ToastUtils 来显示 Toast 不会有这个问题(解决之道就是上面提到的「如何让系统 View 尺寸正常」),当然你也可以自己封装不用我的 ToastUtils;或者参照 CustomToast 来自定义 Toast 布局。

    更大尺寸的设备想要显示更多的内容?

    可以使用 sw 的方案来解决尺寸更大的设备可以显示更多的内容,本方案和 sw 并没有冲突,所以如果你需要在全面屏或者大屏设备显示更多的内容可以创建新的 dimens 来解决,这样就可以做到在某一尺寸范围内的设备显示效果都一致,解决了某些人总是口口声声说「更大的屏幕就应该获取更多的信息啊」。

    enhancement 
    opened by Blankj 22
  • Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033

    Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033

    Describe the bug

    A clear and concise description of what the bug is.

    • The version of utilcode: 1.23.7
    • The device: 小米6
    • The version of device: API 26

    The code of bug

    UriUtils.uri2File
    
    @Override
        protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == 111 && data != null) {
                if (resultCode == Activity.RESULT_OK) {
                    Uri uri = data.getData();
                    File file = UriUtils.uri2File(FilePickerActivity.this, uri);
                    String absolutePath = file.getAbsolutePath();
                }
            }
        }
    

    The stack of crash

    2019-03-08 14:15:38.213 8143-8143/? E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.wiki.cc, PID: 8143
        java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/3033 flg=0x1 }} to activity {com.wiki.cc/com.wiki.cc.ui.a.FilePickerActivity}: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033
            at android.app.ActivityThread.deliverResults(ActivityThread.java:4391)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:4434)
            at android.app.ActivityThread.-wrap19(Unknown Source:0)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1678)
            at android.os.Handler.dispatchMessage(Handler.java:105)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:6701)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
         Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033
            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
            at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
            at android.content.ContentResolver.query(ContentResolver.java:756)
            at android.content.ContentResolver.query(ContentResolver.java:705)
            at android.content.ContentResolver.query(ContentResolver.java:663)
            at com.wiki.cc.util.UriUtils.getFileFromUri(UriUtils.java:120)
            at com.wiki.cc.util.UriUtils.getFileFromUri(UriUtils.java:113)
            at com.wiki.cc.util.UriUtils.uri2File(UriUtils.java:79)
            at com.wiki.cc.ui.a.FilePickerActivity.onActivityResult(FilePickerActivity.java:53)
            at android.app.Activity.dispatchActivityResult(Activity.java:7310)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:4387)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:4434) 
            at android.app.ActivityThread.-wrap19(Unknown Source:0) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1678) 
            at android.os.Handler.dispatchMessage(Handler.java:105) 
            at android.os.Looper.loop(Looper.java:176) 
            at android.app.ActivityThread.main(ActivityThread.java:6701) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783) 
    
    opened by newlai913 21
  • LogUtils能否添加全局TAG后还能显示当前类名的功能

    LogUtils能否添加全局TAG后还能显示当前类名的功能

    比如:全局TAG-MainActivity:---------

    opened by Brainbg 20
  • studio 3.2.1 无法编译

    studio 3.2.1 无法编译

    Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform

    opened by tianshaokai 20
  • ColorUtils.getColor建议

    ColorUtils.getColor建议

    描述需求

    简洁地描述下需求。 ColorUtils.getColor(R.color.color_FFAlpha) ContextCompat.getColor(MainActivity.this, R.color.color_FFAlpha) 两个方法获取的值不一样 查阅了一下源码,发现是因为Utils.getApp().getTheme()和Activity.getTheme()返回的结果不一样的原因 这个其实不算bug,但可能作者当时没有考虑到这个场景......

    可借鉴的

    如果有的话,可以给出一些参考文章、链接、代码

    help wanted 
    opened by qq764215676 0
  • 应用前台后台的需求

    应用前台后台的需求

    希望可以实现应用 前后台 自由切换

    在收到某个指令时 可以实现对 app的 前台后台自由切换

    help wanted 
    opened by greadking 1
  • ToastUtils 在targetsdk升级到30后,调用showS 不显示toast,targetsdk=29时则正常

    ToastUtils 在targetsdk升级到30后,调用showS 不显示toast,targetsdk=29时则正常

    ToastUtils 在targetsdk升级到30后,调用showS 不显示toast,targetsdk=29时则正常

    简洁地描述下 Bug。

    • AndroidUtilCode 的版本:
    • 出现 Bug 的设备型号:
    • 设备的 Android 版本:

    相关代码

    put your code here
    

    异常堆栈

    put the stack of crash here
    

    截图

    如果有的话请添加屏幕截图以帮助解释问题。

    请删除当前行及以下内容

    感谢支持 AndroidUtilCode.

    bug 
    opened by coolBreezes 0
  • FragmentUtils 增加 fragmentTransaction.setMaxLifecycle 支持

    FragmentUtils 增加 fragmentTransaction.setMaxLifecycle 支持

    Androidx Fragment 通过Add() Hide() 方式实现懒加载

    在调用 add 或 show 方法后,setMaxLifecycle(showFragment, Lifecycle.State.RESUMED)

    在调用 hide 方法后,setMaxLifecycle(fragment, Lifecycle.State.STARTED)

    建议 增加fragmentTransaction.setMaxLifecycle 支持

    help wanted 
    opened by xiaoyvyv 0
  • 跳转权限管理界面

    跳转权限管理界面

    如何能跳转到权限管理界面呢?当前只能跳转到应用信息界面

    help wanted 
    opened by yangshengnai 0
  • ThreadUtils内存泄露

    ThreadUtils内存泄露

    描述 Bug

    调用ThreadUtils的executeAtFixedRate相关方法取消后会内存泄露,虽然task cancel了,但是timerTask没有cancel。

    • AndroidUtilCode 的版本:
    • 出现 Bug 的设备型号: Honor 20
    • 设备的 Android 版本: API 30

    相关代码

    ThreadUtils.executeByCachedAtFixRate(task, 1, 1, TimeUnit.SECONDS);
    ThreadUtils.cancel(task);
    

    异常堆栈

    put the stack of crash here
    

    截图

    如果有的话请添加屏幕截图以帮助解释问题。 9fb3e212950aabc329c5b426d572830

    bug 
    opened by haianhsing 2
  • 添加水印功能

    添加水印功能

    请问添加图片水印时,铺满全屏时会被拉伸,文字会变大,请问该怎么处理?

    help wanted 
    opened by lutao2599 1
  • LogUtils 怎么保存 app所有运行日志

    LogUtils 怎么保存 app所有运行日志

    LogUtils 怎么保存 app所有运行日志

    opened by aglszz 2
  • AndroidUtilCode库好用,就是还没迁移到mavenCentral

    AndroidUtilCode库好用,就是还没迁移到mavenCentral

    描述需求

    简洁地描述下需求。

    可借鉴的

    如果有的话,可以给出一些参考文章、链接、代码

    请删除当前行及以下内容

    感谢支持 AndroidUtilCode.

    help wanted 
    opened by lhq1135740561 1
  • use non-sdk method

    use non-sdk method

    https://github.com/Blankj/AndroidUtilCode/blob/64555be9ffd836a0f9bebd916d28d2674930614b/lib/utilcode/src/main/java/com/blankj/utilcode/util/UriUtils.java#L144

    opened by fuzhikai 0
Releases(1.30.0)
To-do list time tracker for programmers and other digital workers with Jira, Github, and Gitlab integration

Please help us improve the app's usability! Organize your daily tasks in one place while making time tracking a lot less annoying. Super Productivity

Johannes Millan 4.1k Sep 18, 2021
The missing Desktop application for Pushbullet.

PB for Desktop PB for Desktop is a lightweight open-source Desktop app for PushBullet. Receive native push notifications on macOS, Windows and Linux.

sidneys.github.io 466 Sep 11, 2021
Receive Android notifications on your mac. (w/PushBullet) ⛺

What is Noti? Noti is your little companion living in your mac menu, relaying any notifications you get on your Android phone with Pushbullet installe

Jari Zwarts 871 Sep 18, 2021
Keep your application settings in sync (OS X/Linux)

Mackup Keep your application settings in sync. Table of content Quickstart Usage What does it do Bullsh*t, what does it really do to my files Supporte

Laurent Raufaste 11.4k Sep 23, 2021
EnvPane - An OS X preference pane for environment variables

EnvPane - A macOS preference pane for environment variables EnvPane is a preference pane for Mac OS X (10.8 or newer) that lets you set environment va

Hannes Schmidt 549 Sep 19, 2021
Menu Bar RSS reader for macOS

baRSS – Menu Bar RSS Reader What is it? A RSS & Atom feed reader that lives in the system status bar. Very much inspired by RSS Menu; go ahead and che

Helena Schobs 34 Sep 16, 2021
MJML: the only framework that makes responsive-email easy

MJML 4 If you're looking for MJML 3.3.X check this branch | Translated documentation | Introduction | Installation | Usage | Contribute | Translated d

MJML 12.5k Sep 14, 2021
Patchman - A macOS application to test APIs with HTTP methods (Decluttered Postman)

A macOS application to test APIs with HTTP methods (Decluttered Postman)

Praneet 139 Sep 6, 2021
Catch: Broadcatching made easy.

Catch: Broadcatching made easy. Catch is the easiest way to do broadcatching on the Mac. Just add your feeds and new episodes will be downloaded as th

Giorgio Calderolla 387 Aug 23, 2021
Read-only mirror of Wireshark's Git repository at https://gitlab.com/wireshark/wireshark. GitHub won't let us disable pull requests. ☞ THEY WILL BE IGNORED HERE ☜ Please upload them at GitLab.

General Information Wireshark is a network traffic analyzer, or "sniffer", for Linux, macOS, *BSD and other Unix and Unix-like operating systems and f

Wireshark Foundation 3.6k Sep 16, 2021
macOS app that allows the control of Spotify and AppleMusic/iTunes music playback from the menu bar.

PlayStatus is a simple macOS app that allows the control of Spotify, Apple Music(macOS 10.15+) and iTunes including iTunes Radio/Beats1 playback from

Nikhil Bolar 79 Sep 16, 2021
A simple but highly customizable `UICollectionViewLayout` for `UICollectionView`.

CollectionViewPagingLayout Layout Designer SnapshotTransformView ScaleTransformView StackTransformView Custom implementations About This is a simple b

Amir Khorsandi 1.4k Sep 15, 2021
ˈyːbɐˌzɪçt

Übersicht Keep an eye on what's happening on your machine and in the world. For general info check out the Übersicht website. Writing Widgets In essen

Felix 3.4k Sep 15, 2021
KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.

KeePassXC KeePassXC is a modern, secure, and open-source password manager that stores and manages your most sensitive information. You can run KeePass

KeePassXC 11.1k Sep 23, 2021
Replacement for MacOS' volume, brightness and keyboard backlight HUDs.

SlimHUD Replacement for MacOS' HUDs. Every day you change your volume or brightness and an ugly and unbelievably old overlay animation appears. SlimHU

Alex Perathoner 133 Sep 13, 2021
Meme Maker open source macOS app made in Swift.

Meme Maker Add text to popular images, share with the world. ##Screens ##Features Select or search a meme from a huge collection. Smart searching opti

Meme Maker 56 Sep 13, 2021
A modern, open source password manager for individuals and teams.

Padloc Simple, secure password and data management for individuals and teams (formerly known as Padlock). This repo is split into multiple packages: P

Padloc 1.1k Sep 13, 2021
a Cocoa GUI for /etc/hosts

Hosts, a system preference pane to manage your hosts file Hosts adds a preference pane to your system preferences which lets you toggle your host file

Voxin Muyli 1.5k Sep 15, 2021
macOS app which assembles and disassembles animated png files

Over 11k downloads* ?? APNGb 2.0.1 (Download) APNGb is a macOS app which creates animated png from a series of png frames and disassembles animated pn

Ștefan Godoroja 233 Sep 6, 2021