开发androidAPI的时候,遇到调用的API地址是内网地址或者是非https的地址,会报如下错误: CLEARTEXT communication to mylocalipaddress not permitted by network security policy 虽然一般情况下,因为安全原因,都需要使用https来调用,有时候因为一些特殊环境,还是需要调用内网IP或者非https的地址 xml下新建 network_security_config.xml,内容如下(把内网或者非https的地址写进去): …

2024-02-02 0条评论 169点热度 0人点赞 admin 阅读全文

开发Android,使用Retrofit,想要增加一个拦截器,代码如下: public static Retrofit initRetrofit() { OkHttpClient client = new OkHttpClient(); client.interceptors().add(chain -> { Request request = chain.request().newBuilder().addHeader("X-Token", "xxxxx").build(); return chain.pr…

2024-02-01 0条评论 333点热度 0人点赞 admin 阅读全文

开发的时候,例如安卓开发,遇到需要将正方形图片转换成圆形显示(如用户头像显示等),这里分享下我使用的Bitmap转换成圆形的工具类,输入Bitmap,输出圆形Bitmap。 直上干货工具方法: /** * 转换图片成圆形 * * @param bitmap * 传入Bitmap对象 * @return */ public static Bitmap toRoundBitmap(Bitmap bitmap) { if (bitmap == null) return null; int width = bitmap.g…

2021-05-03 0条评论 1048点热度 0人点赞 admin 阅读全文

Android开发搜索功能,需要监听输入框,用户实时输入便启动请求后台搜索结果,但是用户快速输入每一个单词,就触发一次服务器请求,有点浪费资源,且体验不好,做法是等待用户比如500ms后,再进行搜索请求,以下是Android代码: class Debounce { private Handler mHandler = new Handler(); private long mInterval; public Debounce(long interval) { mInterval = interval; } publ…

2020-12-22 0条评论 1787点热度 0人点赞 admin 阅读全文