android如何实现开机自动启动Service或app
来源:互联网 发布:windows系统下载 编辑:程序博客网 时间:2024/04/29 10:07
- 今天我们主要来探讨android怎么让一个service开机自动启动功能的实现。Android手机在启动的过程中会触发一个Standard Broadcast Action,名字叫android.intent.action.BOOT_COMPLETED(记得只会触发一次呀),在这里我们可以通过构建一个广播接收者来接收这个这个action.下面我就来简单写以下实现的步骤:
- 第一步:首先创建一个广播接收者,重构其抽象方法 onReceive(Context context, Intent intent),在其中启动你想要启动的Service或app。
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.util.Log;
- public class BootBroadcastReceiver extends BroadcastReceiver {
- //重写onReceive方法
- @Override
- public void onReceive(Context context, Intent intent) {
- //后边的XXX.class就是要启动的服务
- Intent service = new Intent(context,XXXclass);
- context.startService(service);
- Log.v("TAG", "开机自动服务自动启动.....");
- //启动应用,参数为需要自动启动的应用的包名
- Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
- context.startActivity(intent );
- }
- }
- 第二步:配置xml文件,在receiver接收这种添加intent-filter配置
- <receiver android:name="BootBroadcastReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED"></action>
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </receiver>
- 第三步:添加权限 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
http://blog.csdn.net/flying_vip_521/article/details/7053355
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app(转)
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app(转)
- android如何实现开机自动启动Service或app
- lua的一些程序片段
- hdu4279 Number
- Android SERVICE后台服务进程的自启动和保持
- pppd错误码
- Eric5 IDE for Python在window是下安装
- android如何实现开机自动启动Service或app
- hud4278 Faulty Odometer
- 两道选择题 -- 爱
- css去掉li标签前面的点
- SharePoint PeopleEditor 控件的使用
- hdu4282 A very hard mathematic problem
- Linux常用命令详解之文件处理命令二
- 图文讲解 上网本 无光驱 系统蓝屏/系统无法开机 用U盘 winpe 启动U盘 重装系统的方法(通用PE工具箱/老毛桃/大白菜WinPE)
- android的selector,背景选择器用法