xposed模块代码如何得到上下文

最近在学习xoposed开发,刚好需要通过xposed来获取上下文,百度得到以下代码,注意:我还没使用哈;

1
2
3
4
5
6
7
8
9
10
11
12
13
try {
    Class<?> ContextClass = findClass("android.content.ContextWrapper", loadPackageParam.classLoader);
    findAndHookMethod(ContextClass, "getApplicationContext", new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            super.afterHookedMethod(param);
            Context applicationContext = (Context) param.getResult();
            XposedBridge.log("得到上下文");
        }
    });
} catch (Throwable t) {
    XposedBridge.log("获取上下文出错"+t);
}