1 PackageCom.example.lenovo.guangbo;2 3 ImportAndroid.app.Service;4 Importandroid.content.Intent;5 ImportAndroid.os.IBinder;6 ImportAndroid.util.Log;7 8 Public classMyServiceextendsService {9 PublicMyService () {TenLOG.E ("TAG", "Boot Successful"); One } A - @Override - Publicibinder onbind (Intent Intent) { the //Todo:return The communication channel to the service. - Throw NewUnsupportedoperationexception ("not yet implemented"); - } - } + -MyService
1 PackageCom.example.lenovo.guangbo;2 3 ImportAndroid.content.BroadcastReceiver;4 ImportAndroid.content.Context;5 Importandroid.content.Intent;6 ImportAndroid.util.Log;7 8 Public classKaijiqdextendsBroadcastreceiver {9 PublicKAIJIQD () {Ten } One A @Override - Public voidOnReceive (Context context, Intent Intent) { - theLOG.E ("TAG", "Receive boot complete broadcast"); - //Start the service -Context.startservice (NewIntent (Context,myreceiver.class)); - } + } - +Kaijiqd.java
1<Service2Android:name= ". MyService "3Android:enabled= "true"4Android:exported= "true"/>5 6<receiver7Android:name= ". KAIJIQD "8Android:enabled= "true"9Android:exported= "true" >Ten<intent-filter> One<action android:name= "Android.intent.action.BOOT_COMPLETED" > A -</action> -</intent-filter> the</receiver> - -Androidmanifest
<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED" ></uses-permission>
Android Start-up service