赞
踩
- package com.doshare.boardroom.broadcastreceiver;
-
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
-
- import com.doshare.boardroom.view.activity.HomeActivity;
- public class BootBroadcastReceiver extends BroadcastReceiver {
- static final String ACTION = "android.intent.action.BOOT_COMPLETED";
- @Override
- public void onReceive(Context context, Intent intent) {
- if(intent.getAction().equals(ACTION)){
- Intent myIntent = new Intent(context, HomeActivity.class);
- myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(myIntent);
- }
- }
- }
二、在AndroidManifest.xml文件的<application>标签中写入下列代码
- <!--name中传入的是开机自启广播接收器的相对路径-->
- <receiver
- android:name=".broadcastreceiver.BootBroadcastReceiver"
- android:exported="true">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。