Android开机启动应用和服务
注册广播监听开机状态,启动应用和服务等;
监听开机的广播接收器:
public class BootCompletedReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
//开机启动服务
Intent it= new Intent("com.test.action.testservice");
context.startService(it);
//启动应用
Intent act= new Intent("com.test.action.testactivity");
context.startActivity(act);
}
}
在Manifest.xml中注册监听开机的广播:
<receiver android:name="com.test.BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
添加开机状态的权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>