注册清单文件
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
创建一个BootBroadCastReceiver类
import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;/** * Created by Liqf on 2017.09.20. */public class BootBroadCastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { //example:启动程序 Intent start = new Intent(context, MainActivity.class); start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// context.startActivity(start); } }}
//在主方法里做你想做的操作