怎么知道Android手机会睡觉?

怎么知道Android手机会睡觉? 请帮我一个示例代码。 谢谢阅读。     
已邀请:
您需要为Intent.ACTION_SCREEN_OFF注册广播接收器 所以,创建广播接收器 这是您处理screen_off意图的地方。
private BroadcastReceiver receiver = new BroadcastReceiver() {
public void onReceive(final Context context, final Intent intent) {

    /*
     * dispatch screen_off
         * to handler method
     */

    String iAction = intent.getAction();

    if (iAction.equals(Intent.ACTION_SCREEN_OFF))
    handleScreenAction(iAction);

}

};
现在过滤器注册接收器。
static void registerReciever() {
    IntentFilter myFilter = new IntentFilter();
    // Catch screen off event
    myFilter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(receiver, myFilter);
}
    

要回复问题请先登录注册