10月1 假期归来,回顾线上app 功能及bug 回馈检查时,发现 Android 11 系统 app 出现的一系列问题
1、首先是原有使用反射获取的 Toast view 出现空, 通过反射获取 状态栏的view 出现空异常
2、使用第三方的PictureSelector 图片选择器 出现异常,不能正常加载相册图片
针对以上两个问题展开排查
1、具体问题应该是反射路径或地址修正了,可使用以下方法
public static int getStatusBarHeight(Context context) {
// int statusBarHeight = 0;
// try {
//
// @SuppressLint("PrivateApi") Class<?> c = Class.forName("com.android.internal.R$dimen");
// Object o = c.newInstance();
// Field field = c.getField("status_bar_height");
// int x = (Integer) field.get(o);
// statusBarHeight = context.getApplicationContext().getResources().getDimensionPixelSize(x);
// } catch (Exception e) {
// e.printStackTrace();
// }
// return statusBarHeight == 0 ? dip2px(context, 25) : statusBarHeight;
int result = 0;
int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = Resources.getSystem().getDimensionPixelSize(resourceId);
}
return result;
}
2、具体问题是,getContentResolver().query 的 sortOrder 参数 只支持 排序,不再支持 order by ,group by 等语句,
查看源码可知
最终把所有方法参数 转换伟bundle 传给 query 进行查询
跟踪代码后 Android R 新增了 ContentResolver#QUERY_ARG_SQL_LIMIT 条件,那么是不是咱们就可以把
limit 语句放到 budle 呢?
具体修改方案如下: