应用开发时有时候需要一些服务 在开机 后启动 ,在Android或者OPhone中实现开机启动很简单,只需实现一个Receiver即可。一个简单的Demo如下:
1.首先实现一个Reveiver:
public class TestBootReceiver extends BroadcastReceiver {
/* action to receive for an intent */
private static final String TAG = "TestBootReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, " get ACTION:" + action);
if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i(TAG, "Start your service here...");
}
}
}
2.把Receiver添加到Manifest当中:
<receiver android:name=".test.TestBootReceiver ">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>