【Android】程序自启动,跳过主桌面(Launcher)
2014-12-17 15:56
573 查看
最近项目需要做一个安卓端的控制程序,其中一条需求就是开机自动启动,按照网上很多说说法是通过BroadcastReceiver的方式去实现的,之前使用这样的方法还算可以,开进进入主桌面,很快就能跳转到自己的应用程序中,但是这次买的新板子,不知道是硬件配置问题还是各个厂商提供的系统差异性,新板子以这种方式实现开机启动,会在主桌面(Launcher)停留很长时间,让人无法接受,因此第一想法就是是否能通过删除Launcher的方式来解决这个问题(Launcher通常存放在/system/app/Launcher2.apk,如何删除参考http://blog.csdn.net/hua583999775/article/details/41981315),删除后发现系统一直停留在开机界面(就是android闪耀的界面),根本不会进入自己的程序,然后就想自己的程序是否能替代Launcher的功能呢,网上找了些资料,下面做一下总结。
首先讲一下BroadcastReceiver的方式实现开机自起的功能:
BroadcastReceiver是广播机制,系统完全启动后会发出一个BOOT_COMPLETED的广播,我们创建一个类,继承BroadcastReceiver,实时监听BOOT_COMPLETED的广播消息,监听到后启动我们自己的应用程序即可,代码如下
public class AutoBootBroadcase extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent intent1 = new Intent();
intent1.setClass(context, MainActivity.class);
intent1.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
}
}在AndroidManifest.xml文件中申明这个类
<receiver
android:name=".AutoBootBroadcase">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
另一种方法就是模仿Launcher,让我们的程序实现Launcher的功能,据了解系统启动后,由ActivityManager调用Launcher(网上查阅的资料,还有待证实),AcitvityManager会启动拥有CATEGORY_HOME属性的Activity,Laucher的<intent-filter>是这么描述的
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>一定程度上也验证了上面的说法,我们只需要在我们的应用的主Activity的<intent-filter>中添加<category android:name="android.intent.category.Home"/>就可以实现类似Launcher的功能了,具体还是需要了解安卓的启动原理,Launcher的启动机制才能很好的去解决这个问题,这边由于项目时限问题,做个记录,等有时间再好好研究。
首先讲一下BroadcastReceiver的方式实现开机自起的功能:
BroadcastReceiver是广播机制,系统完全启动后会发出一个BOOT_COMPLETED的广播,我们创建一个类,继承BroadcastReceiver,实时监听BOOT_COMPLETED的广播消息,监听到后启动我们自己的应用程序即可,代码如下
public class AutoBootBroadcase extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent intent1 = new Intent();
intent1.setClass(context, MainActivity.class);
intent1.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
}
}在AndroidManifest.xml文件中申明这个类
<receiver
android:name=".AutoBootBroadcase">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
另一种方法就是模仿Launcher,让我们的程序实现Launcher的功能,据了解系统启动后,由ActivityManager调用Launcher(网上查阅的资料,还有待证实),AcitvityManager会启动拥有CATEGORY_HOME属性的Activity,Laucher的<intent-filter>是这么描述的
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>一定程度上也验证了上面的说法,我们只需要在我们的应用的主Activity的<intent-filter>中添加<category android:name="android.intent.category.Home"/>就可以实现类似Launcher的功能了,具体还是需要了解安卓的启动原理,Launcher的启动机制才能很好的去解决这个问题,这边由于项目时限问题,做个记录,等有时间再好好研究。
相关文章推荐
- Android中程序向桌面和Launcher添加快捷方式
- Android 跳过开机界面 直接软件自启动 Android做自己的桌面 替代原生桌面 Android开发自己桌面
- 修改android 修改系统程序图标大小,android4.0 Launcher2 桌面的列数,行数
- Android中程序向桌面和Launcher添加快捷方式【安卓进化三十二】
- android 开机启动桌面程序,launcher模式
- android 桌面程序 滑动抽屉 SlidingDraw,一个小小的demo
- Android Launcher桌面循环
- Android Launcher桌面图标的加载和存储
- android让程序开机自启动
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android中源码Launcher主屏幕程序排列详解【安卓Launcher进化一】
- Android Widget进阶——桌面便笺程序实例的实现流程与美化设计(图)
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- 说说Android桌面(Launcher应用)背后的故事(二)——应用程序的添加
- Android Launcher中桌面图标的加载和存储
- 定制你自己的android手机桌面Launcher===一个完成Launcher开发的介绍-第二篇
- android 开机自启动程序2
- 开发android的桌面小程序AppWidget
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- Android开机自启动程序