有会JAVA的大佬吗?一个简单超的问题。如何获取Activity
本帖最后由 qjmfktlf 于 2022-4-14 00:38 编辑大佬们,我是刚学JAVA。这个问题百度了一个星期找不到解决方法,无奈求助大佬们。
我想要在MainXposed类里面发送广播。但是MainXposed类里面MainActivity要怎么获取啊?
这是MainXposed类
//hook数据库插入操作
private void hookDatabaseInsert(final XC_LoadPackage.LoadPackageParam loadPackageParam) {
Class<?> classDb = XposedHelpers.findClassIfExists("com.tencent.wcdb.database.SQLiteDatabase", loadPackageParam.classLoader);
XposedHelpers.findAndHookMethod(classDb, "insertWithOnConflict", String.class, String.class, ContentValues.class, int.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String tableName = (String) param.args;
ContentValues contentValues = (ContentValues) param.args;
String strTalker = contentValues.getAsString("talker");//说话人ID
int isSend = contentValues.getAsInteger("isSend");//1:是不是自己发送的消息
if ((tableName.equals("message")) && (isSend == 0)){ //是微信消息&&是某群消息
WeChatReply wechat = new WeChatReply();
wechat.sendIntent(activity,strTalker,"自动回复");
}
}
});
}
这是WeChatReply 类public class WeChatReply extends AppCompatActivity {
public void sendIntent (Activity act,String addressee,String text){
Intent intent=new Intent("toTasker");
Bundle bundle = new Bundle();
bundle.putString("sean1", addressee);
bundle.putString("sean2", text);
intent.putExtras(bundle);
act.sendBroadcast(intent);
}
}
public class Hook implements IXposedHookLoadPackage {
public static Activity 上下文;
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
//判断是不是这个软件包名,不判断的话,全部的软件都会被hook
if (!lpparam.packageName.equals("com.mycompany.myapp"))
return;
//提示("已hook的包名∶" + 包名.packageName);
if (上下文 == null) {
XposedHelpers.findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
if (上下文 == null) {
上下文 = (Activity) param.thisObject;
XposedBridge.log("得到Activity上下文");
}
}
});
}
}
} 小骚 发表于 2022-4-15 19:32
public class Hook implements IXposedHookLoadPackage {
public static Acti ...
大佬,你这个我看不懂啊,
我的问题前两天已经解决了。
看了 奋进的代码 大佬的教程。还是谢谢你,对了你的代码是啥意思
XposedHelpers.findAndHookMethod(ContextThemeWrapper.class, "attachBaseContext",Context.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
context=(Context) param.args;
}
});
页:
[1]