广播事件处理broadcast receiver---系统启动完成提示

采用标准的广播Action常量----android.intent.action.BOOT_COMPLETED

 

step1, 建立Activity工程

step2,添加一个新类名字为MyReceiver,继承BroadcastReceiver,重新实现其onReceive。如下:

@Override
 public void onReceive(Context context, Intent intent) {
  // TODO Auto-generated method stub
  Log.i(“hello","BOOT_COMPLETED");
 }

 

step3,在功能配置单添加上(注册)android.intent.action.BOOT_COMPLETED

<receiver
                android:name=".MyReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />       
              
            </intent-filter>

注意:

还有权限许可:uses-permission

android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
   
    <uses-permission />

重启机盒:出现:

为了能开机运行Service,可在下面加上

@Override
 public void onReceive(Context context, Intent intent) {
  // TODO Auto-generated method stub
    Intent intent=new (context,yourLaunchService.class);//here

context.startService(intent);
 }

yourLaunchService 是你的开发的任意service.

你可能感兴趣的:(广播事件处理broadcast receiver---系统启动完成提示)