Sunzxyong/Tiny

Android P Q 适配问题

pinguo-sunjianfei opened this issue · 0 comments

private static Application getApplication() {
    Application application = null;
    Method method;
    try {
        method = Class.forName("android.app.AppGlobals").getDeclaredMethod("getInitialApplication");
        method.setAccessible(true);
        application = (Application) method.invoke(null);
    } catch (Exception e) {
        try {
            method = Class.forName("android.app.ActivityThread").getDeclaredMethod("currentApplication");
            method.setAccessible(true);
            application = (Application) method.invoke(null);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return application;
}

这段代码在android Q P上存在适配问题