这里总结下我研究这个需求,想出的两种解决方案。
第一种方法最简单暴力只要修改apk的AndroidManifest直接上源码
这里就加了一句android:priority=”2”,这样在开机和按HOME键时候系统intent判断到category.HOME属性后如果有多个此属性apk,则会进入ResolverActivity让用户选择。当你定义了此优先级它其他未定义的都默认为0,所以优先进入了你的activity。
第二种方法需要修改framework源码来强制进入你的launcher
首先ActivityManagerService.java中
boolean startHomeActivityLocked(int userId) {
if (mHeadless) {
// Added because none of the other calls to ensureBootCompleted seem to fire
// when running headless.
ensureBootCompleted();
return false;
}
if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL
&& mTopAction == null) {
// We are running in factory test mode, but unable to find
// the factory test app, so just sit around displaying the
// error message and don't try to start anything.