1、添加权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
2、注册静态广播
<receiver android:name=".broadcast.BootUpReceiver">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
3、
public class BootUpReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { PackageManager packageManager = null; String action = intent.getAction(); if((Intent.ACTION_BOOT_COMPLETED).equals(action)){ Intent i = new Intent(context, MainActivity.class); Log.d("wxwx","---------BootUpReceiver---------------"); // 也可以这样:Intent i = packageManager.getLaunchIntentForPackage("com.gfw.mycup/.broadcast.BootUpReceiver"); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } } 4、运行在手机上,再把手机重启,或是用adb来重启:adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n "com.gfw.mycup/.broadcast.BootUpReceiver"