Android9上弹出dialog中的内容是Detected problems with api compatibility(visit.g.co/appcompat for more info)

本文介绍了Android P中出现的API兼容性问题,由于谷歌限制了对非SDK接口的调用,导致可能出现Detected problems with api compatibility的弹窗。通过反射方式可以关闭此警告,具体解决方案是在APP启动时执行相应反射代码来设置隐藏API警告已显示。
摘要由CSDN通过智能技术生成

Detected problems with api compatibility(visit.g.co/appcompat for more info)其实就是检测到api兼容性问题(visit.g.co/appcompat了解更多信息)。

查了一下,发现是 Android P 后谷歌限制了开发者调用非官方公开API 方法或接口,也就是说,你用反射直接调用源码就会有这样的提示弹窗出现,非 SDK 接口指的是 Android 系统内部使用、并未提供在 SDK 中的接口,开发者可能通过 Java 反射、JNI 等技术来调用这些接口。但是,这么做是很危险的:非 SDK 接口没有任何公开文档,必须查看源代码才能理解其行为逻辑。
但是源码是JAVA写的,万物皆可反射,所以还是可以用反射干掉这个 每次启动都会弹出的提醒窗口:

解决方法是在APP启动的时候调用下面的这个方法,方法如下:

private void closeAndroidPDialog(){
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } c

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现这个效果,可以通过自定义一个 Dialog,将其设置为无标题,设置宽度为屏幕宽度,高度为输入法高度,让其紧贴输入法顶部。代码如下: ```java public class InputDialog extends Dialog { private View mContentView; private int mInputHeight; public InputDialog(Context context) { super(context, R.style.InputDialogTheme); init(context); } private void init(Context context) { // 获取输入法高度 mInputHeight = getInputMethodHeight(context); // 设置无标题 requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置宽度为屏幕宽度 WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = mInputHeight; getWindow().setAttributes(layoutParams); // 设置布局 mContentView = LayoutInflater.from(context).inflate(R.layout.dialog_input, null); setContentView(mContentView); } public void show(View view) { // 显示Dialog super.show(); // 让Dialog紧贴输入法顶部 Window window = getWindow(); window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.y = -mInputHeight; window.setAttributes(layoutParams); // 设置输入框获取焦点 EditText editText = mContentView.findViewById(R.id.edit_text); editText.requestFocus(); } private int getInputMethodHeight(Context context) { int height = 0; Rect rect = new Rect(); View decorView = getWindow().getDecorView(); decorView.getWindowVisibleDisplayFrame(rect); int screenHeight = decorView.getRootView().getHeight(); if (screenHeight - rect.bottom > 0) { height = screenHeight - rect.bottom; } return height; } } ``` 其,`dialog_input` 是输入框布局,可以根据需要自行修改。在 Activity ,当需要弹输入框时,可以这样使用: ```java InputDialog dialog = new InputDialog(this); dialog.show(getWindow().getDecorView()); ``` `getWindow().getDecorView()` 可以获取当前 Activity 的根布局,这样就可以让 Dialog 紧贴输入法顶部了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值