机器人临睡前(待机) [英] Android going to sleep (standby)

查看:245
本文介绍了机器人临睡前(待机)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Andr​​oid设备进入睡眠状态(屏幕关闭),有一个人的想法怎么办呢?


  • 在过去,我用的是电源管理函数 goToSleep(时间),但显然这个功能不存在了,我不明白为什么。


  • 其他主题谈论这些行:

     电源管理PM =(电源管理)getSystemService(Context.POWER_SERVICE);
        激活锁定= pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,我wakelook);
        wakeLock.acquire();


但只允许该设备进入睡眠模式,瞒着他到睡眠模式了。


  • 我已经尝试过其中包括减少屏幕的亮度的解决方案,但它不是因为设备没有真正进入睡眠模式,真正解决问题。而且我不希望使用下面的code:

      android.provider.Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT,timeoutInactivity);

    因为我不想触摸屏幕显示设置,它是一个多解决方案,一个解决方法。


PS:这是一个系统的应用程序,所以我没有任何权利/许可限制


解决方案

 私人PowerManager的mPowerManager;
私人PowerManager.WakeLock mWakeLock;公共无效睡眠(){
      mWakeLock = mPowerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,标签);
      mWakeLock.acquire();
}

试试这个

I want my android device to go to sleep (screen off), has someone an idea how to do it?

  • In the past I was using the PowerManager function goToSleep(time), but apparently this function does not exist anymore, I don't understand why.

  • Other topics talk about those lines:

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My wakelook");
        wakeLock.acquire();
    

But it only allows the device to enter sleep mode, without telling him to go to sleep mode now.

  • I already tried the solution which consists of diminishing the luminosity of the screen, but it is not a real solution since the device doesn't really enter sleep mode. And I don't want to use the following code:

    android.provider.Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, timeoutInactivity);
    

    because I don't want to touch the screen display settings and it is more a workaround than a solution.

PS : It's for a system app, so I don't have any right/permission limitation.

解决方案

private PowerManager mPowerManager;
private PowerManager.WakeLock mWakeLock;

public void sleep(){
      mWakeLock = mPowerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
      mWakeLock.acquire();
}

Try this

这篇关于机器人临睡前(待机)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆