像标题一样,我想挂接第三个应用程序,并可以从第三个应用程序的活动中调用我的应用程序活动,所以我想获取第三个应用程序的上下文,我该怎么办?
第三个应用程序的包是com.ss.android.gallery.heavy,我的项目的包是com.example.hao.hookstartupinterfacetest;
我的Xposed Module.java(MainActivity是我的项目的活动)
XposedHelpers.findAndHookMethod("com.ss.android.gallery.heavy.activity.SplashActivity",
loadPackageParam.classLoader, "getMainIntent", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
Context context = (Activity)methodHookParam.getResult();
return new Intent(context, MainActivity.class);
}
});
SplashActivity.class(在第三个应用程序中,MainActivity在这里属于第三个应用程序.)
public class SplashActivity extends BaseSplashActivity{
protected Intent getMainIntent(){
return new Intent(this, MainActivity.class);
}
}
错误
01-18 20:38:23.669 4730-4730/com.ss.android.gallery.heavy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ss.android.gallery.heavy, PID: 4730
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ss.android.gallery.heavy/com.example.hao.hookstartupinterfacetest.MainActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at com.ss.android.gallery.base.activity.BaseSplashActivity.goMainActivity(BaseSplashActivity.java:61)
at com.ss.android.gallery.base.activity.BaseSplashActivity.access$000(BaseSplashActivity.java:17)
at com.ss.android.gallery.base.activity.BaseSplashActivity$1.run(BaseSplashActivity.java:76)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
解决方法:
您正在尝试直接使用挂钩应用程序的上下文来启动应用程序的活动,由于该活动实际上不是挂钩应用程序的一部分,因此该操作不起作用(因此出现“未在AndroidManifest.xml中定义”错误).创建意图时,必须明确指定应用程序包和类的全名:
Intent intent = new Intent();
intent.setClassName(
// Your app's package name
"com.example.hao.hookstartupinterfacetest",
// The full class name of the activity you want to start
"com.example.hao.hookstartupinterfacetest.MainActivity");
return intent;
您还应该在AndroidManifest.xml内将MainActivity的android:exported属性设置为true,以便可以通过挂钩的应用程序启动它.
另外,Context context =(Activity)methodHookParam.getResult();应该可能是Context context =(Activity)methodHookParam.thisObject ;,尽管您实际上根本不需要使用此方法.
标签:xposed,android
来源: https://codeday.me/bug/20191111/2022624.html