BootReceiver.java
package com.hanqi.testbr; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class BootReceiver extends BroadcastReceiver { public BootReceiver() { Log.e("ATG","构造开机完成广播接收器"); } @Override public void onReceive(Context context, Intent intent) { Log.e("ATG","广播接收器自动启动Service"); //启动服务 context.startService(new Intent(context,BootService.class)); } }
BootService.java
package com.hanqi.testbr; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.support.annotation.Nullable; import android.util.Log; /** * Created by Administrator on 2016/4/25. */ public class BootService extends Service { @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); Log.e("ATG", "服务自动启动的"); } }
时间: 2024-10-09 22:14:27