Android APP开机自启,Xposed解决方案

来源:互联网 发布:mac地址定位软件 编辑:程序博客网 时间:2024/04/29 14:02

公司某Android TV项目需要应用开机自启,进入应用界面。
使用的是创维T2盒子, 普通解决方式无法解决问题,应该是厂商进行了限制,无法自启。

最后使用Xposed解决了。该方式应该同样适用于可以root的其他手机/盒子。

  1. root设备。我使用360root成功root了创维T2盒子,其它设备请自行尝试。
  2. 安装xposed框架
  3. 编写xposed 模块。
  4. 安装使用

编写xposed 模块

请自行搜索教程,结合下面的代码

1.manifest文件

<manifest package="com.wiseljz.wechatretransform"          xmlns:android="http://schemas.android.com/apk/res/android">    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <meta-data            android:name="xposedmodule"            android:value="true" />        <meta-data            android:name="xposeddescription"            android:value="开机自启" />        <meta-data            android:name="xposedminversion"            android:value="46" />    </application></manifest>

2 编写XposedInit文件。其它设备请自行查找launcher的包名和要hook的方法。

package com.wiseljz.autostart;import android.content.Context;import android.content.Intent;import de.robv.android.xposed.IXposedHookLoadPackage;import de.robv.android.xposed.XC_MethodHook;import de.robv.android.xposed.callbacks.XC_LoadPackage;import static de.robv.android.xposed.XposedHelpers.callMethod;import static de.robv.android.xposed.XposedHelpers.callStaticMethod;import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;import static de.robv.android.xposed.XposedHelpers.findClass;/** * Created by l.wang (516066490@qq.com) on 2017/8/8. */public class XposedInit implements IXposedHookLoadPackage{    @Override    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {        //找到launcher的包名,hook Application的onCreate方法        //com.skyworthdigital.sky2dlauncherv4        if(loadPackageParam.packageName.contains("sky2dlauncherv4")){            findAndHookMethod("com.skyworthdigital.sky2dlauncherv4.SkyApplication", loadPackageParam.classLoader, "onCreate", new XC_MethodHook()            {                @Override                protected void afterHookedMethod(MethodHookParam param) throws Throwable {                    Object activityThread = callStaticMethod(findClass("android.app.ActivityThread", null), "currentActivityThread");                    Context mContext = (Context) callMethod(activityThread, "getSystemContext");                    //自己应用的隐式启动action                    Intent intent = new Intent("com.wiseljz.sample.action");                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                    mContext.startActivity(intent);                }            });        }    }}

3.定义入口,asserts文件夹下xposed_init文件,文件中写上上面文件的路径

com.wiseljz.autostart.XposedInit

4 build.gradle文件

如果报错
class ref in pre-verified class resolved to unexpected implementation

将XposedBridgeApi-54.jar 放到lib目录下,使用下面的语句,

    provided fileTree(include: ['*.jar'], dir: 'lib')    compile fileTree(include: ['*.jar'], dir: 'libs')
原创粉丝点击