1.广播有哪些类型
-
开机广播
-
网络状态广播
-
关机广播
2.注册广播方式
2.1 静态注册
在AndroidMainfest中注册
<receiver android:name="com.example.reboottest.BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
当收到对应的开机广播后,则在BroadcastReceiver中进行相应的接收
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
if (PreferencesUtil.getBoolean(context, "AUTO_REBOOT", false)) {
Intent acIntent = new Intent(context, MainActivity.class);
acIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(acIntent);
}
}