android 9.0私有api弹框提示解决方案

在android9.0系统手机中,启动app会发现系统弹出了一个包含如下信息的提示框:Detected problems with API compatibility(visit g.co/dev/appcompat for more info)
经过搜索引擎查证,并亲测,在application类中,添加如下方法并调用,即可解决问题

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        disableAPIDialog();
        }

     /**
     * android 9.0 调用私有api弹框的解决方案
     */
    private void disableAPIDialog(){
        try {
            Class clazz = Class.forName("android.app.ActivityThread");
            Method currentActivityThread = clazz.getDeclaredMethod("currentActivityThread");
            currentActivityThread.setAccessible(true);
            Object activityThread = currentActivityThread.invoke(null);
            Field mHiddenApiWarningShown = clazz.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(android 9.0私有api弹框提示解决方案)