码迷,mamicode.com
首页 > 其他好文 > 详细

XposedNoRebootModuleSample 不需要频繁重启调试的Xposed 模块源码例子

时间:2016-05-10 20:20:09      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

XposedNoRebootModuleSample(不需要频繁重启调试的Xposed 模块源码例子)
Xposed Module Sample No Need To Reboot When Debug

github:https://github.com/asiontang/XposedNoRebootModuleSample
    @Override
    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable
    {
        if (!"cn.asiontang.location.demo".equals(loadPackageParam.packageName))
            return;
        try
        {
            //在发布时,直接调用即可。
            if (!BuildConfig.DEBUG)
            {
                handleLoadPackage4release(loadPackageParam);
                return;
            }
            //在调试模式为了不频繁重启,使用反射的方式调用自身的指定函数。

            /*【方法2】*/
            final String packageName = MainXposedHook.class.getPackage().getName();
            String filePath = String.format("/data/app/%s-%s.apk", packageName, 1);
            if (!new File(filePath).exists())
            {
                filePath = String.format("/data/app/%s-%s.apk", packageName, 2);
                if (!new File(filePath).exists())
                {
                    XposedBridge.log("Error:在/data/app找不到APK文件" + packageName);
                    return;
                }
            }
            final PathClassLoader pathClassLoader = new PathClassLoader(filePath, ClassLoader.getSystemClassLoader());
            final Class<?> aClass = Class.forName(packageName + "." + MainXposedHook.class.getSimpleName(), true, pathClassLoader);
            final Method aClassMethod = aClass.getMethod("handleLoadPackage4release", XC_LoadPackage.LoadPackageParam.class);
            aClassMethod.invoke(aClass.newInstance(), loadPackageParam);

            /*【方法1】:无法达到效果*/
            //final Class<MainActivity> pathClassLoader = MainActivity.class;
            //final Class<?> aClass = Class.forName(pathClassLoader.getPackage().getName() + "." + MainXposedHook.class.getSimpleName(), true, pathClassLoader.getClassLoader());
            //final Method aClassMethod = aClass.getMethod("handleLoadPackage4release", XC_LoadPackage.LoadPackageParam.class);
            //aClassMethod.invoke(aClass.newInstance(), loadPackageParam);
        }
        catch (final Exception e)
        {
            XposedBridge.log(e);
        }
    }

    public void handleLoadPackage4release(final XC_LoadPackage.LoadPackageParam loadPackageParam)
    {
        XposedBridge.log("------------5");
    }

 

XposedNoRebootModuleSample 不需要频繁重启调试的Xposed 模块源码例子

标签:

原文地址:http://www.cnblogs.com/AsionTang/p/5478761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!