package com.aoleyun.sn.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import com.aoleyun.sn.utils.JgyUtils; import com.aoleyun.sn.utils.PowerOffAlarmUtils; /** * 定时关机广播接收器 *
* 由 {@link PowerOffAlarmUtils} 通过 AlarmManager 的精确闹钟触发。 * 使用 manifest 静态注册,应用进程被杀掉后依然能被系统拉起并执行关机。 * * @author aoleyun */ public class PowerOffReceiver extends BroadcastReceiver { private static final String TAG = "PowerOffReceiver"; @Override public void onReceive(Context context, Intent intent) { String action = null == intent ? null : intent.getAction(); Log.e(TAG, "onReceive: " + action); if (!PowerOffAlarmUtils.ACTION_POWER_OFF_ALARM.equals(action)) { return; } //先安排下一次(循环定时关机),再关机,避免关机过程中闹钟安排失败 PowerOffAlarmUtils.schedule(context); Log.e(TAG, "onReceive: 设备关机"); JgyUtils.getInstance().shutdown(); } }