之前写插件,有时候莫名其妙的就失效了,但是xposed installer中显示是勾选中的状态。所以就在自身的模块中加一个小的检测功能,来判断模块是否启动。
原理很简单,在开发者论坛中找到的:
就是在MainActivity实现一个boolean方法,然后用xposed hook自己的函数。能hook成功,自然代表模块成功启动了,反之亦然。
// MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!isModuleActive()){
Toast.makeText(this, "模块未启动", LENGTH_LONG).show();
}
else {
Toast.makeText(this, "模块已启动", LENGTH_LONG).show();
}
}
private boolean isModuleActive(){
return false;
}
hook自己
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
// Xposed模块自检测
if (loadPackageParam.packageName.equals("your.package.name")){
XposedHelpers.findAndHookMethod("your.package.name.MainActivity", loadPackageParam.classLoader, "isModuleActive", XC_MethodReplacement.returnConstant(true));
}
}
这样,如果模块成功激活,就会在启动app的时候弹一个toast--模块已启动