开机启动Receiver
1 public void onReceive(Context context, Intent intent) {
2 String action = intent.getAction();
3 if(Intent.ACTION_BOOT_COMPLETED.equals(action)) {
4 Intent serviceIntent = new Intent();
5 serviceIntent.setClass(context, BcsService.class);
6 context.startService(serviceIntent);
7 }
8 }
开机和网络连接时启动Receiver
1 @Override
2 public void onReceive(Context context, Intent intent) {
3 String action = intent.getAction();
4 if(Intent.ACTION_BOOT_COMPLETED.equals(action) ||
5 ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
6 Intent serviceIntent = new Intent();
7 serviceIntent.setClass(context, BcsService.class);
8 context.startService(serviceIntent);
9 }
10 }