Android 静态注册
Android7.0 及以下版本
本例子的ACTION 仅支持Android7.0 及以下版本
/**
-
第一步,写一个子类继承BroadcastReceiver
*/
public class BootReceiver extends BroadcastReceiver {@Override
public void onReceive(Context context, Intent intent) {
Log.d(“BootReceiver”,“开机完成”+intent.getAction());
Toast.makeText(context,“开机完成”,Toast.LENGTH_SHORT).show();
}
}
第二步,在xml里面注册广播
<receiver android:name=".BootReceiver">
<!-- 第三步,在intent-filter添加条件 -->
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
第四步,有些Action需要添加权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<