Xposed之app内直接页面跳转思路

有时候我们想在某个app内不用手点击就跳转到指定的页面,比如打开新闻app首页后想直接跳转到指定文章内。
首先想到的是andord开发页面跳转传值一般用的是Extra,那么需要先hook到文章详情页看看接受到传过来的值有哪些,我们才能在首页跳转时候把值传过去。

1、查看详情页,看看app正常点击打开文章传过来的值有哪些,hook到详情页的包名和activity名字全路径。然后手动后点击跳转时候会打印传过来的值。

Class<?> mainActivity = XposedHelpers.findClass("xxx.xxxx.xxxxx", classLoader);
XposedHelpers.findAndHookMethod(mainActivity, "onCreate", Bundle.class, new XC_MethodHook() {
    @Override
    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
        super.beforeHookedMethod(param);
    }

    @Override
    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
        super.afterHookedMethod(param);
        Activity activity = (Activity) param.thisObject;
        if (activity != null) {
            Intent getIntent = activity.getIntent();
            Bundle bundle = getIntent.getExtras();
            for (String key : bundle.keySet()) {
                Log.i("extras", "Key=" + key + ", content=" + bundle.getString(key));
            }
        }
    }
});

2、打印出来正常打开文章传过来的值有哪些,然后我们在打开app首页时候直接调起文章详情页面,传值就好了。这样就不用手点击自动打开文章了。

   Class<?> mainActivity = XposedHelpers.findClass("xxxx.xxxx.xx.MainActivity", classLoader);
        XposedHelpers.findAndHookMethod(mainActivity, "onCreate", Bundle.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                final Activity activity = (Activity) param.thisObject;
                if (activity != null) {
                    Log.e("hook", "获取到上下文");
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id", "1111111111");
                    jsonObject.put("title", "王者小鳄鱼");
                    jsonObject.put("msg", "111111");
                    Intent intent = new Intent();
                    intent.setClassName(activity, "xxxx.xxx.文章详情页面activity");
                    intent.putExtra("imd", "1");
                    intent.putExtra("meg", "23");
                    intent.putExtra("json", jsonObject.toString());
                    activity.startActivity(intent);
                }
            }
        });

这样就可以再打开app时候直接跳转到指定文章的详情页面了,这里传的值有文章id等

发布了45 篇原创文章 · 获赞 22 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_24542767/article/details/103526560