检查省电模式Programically [英] Checking for Power Saver Mode Programically

查看:347
本文介绍了检查省电模式Programically的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个应用程序(AutoWifiSwitch)和我计划增加自动禁用我的应用程序的无线扫描服务是否启用省电模式的特点之一。

I have written an app (AutoWifiSwitch) and one of the features I plan to add is automatically disabling the wifi scanning service in my app if power saving mode is enabled.

我知道Android的L被认为具有电池节能实施(previously HTC和三星将自身添加功能的软件)。 presumably这现在意味着谷歌将增加一些它的API。理想情况下,将是一个新的动作加入,所以我可以听的。

I know Android L is supposed to have Battery Saving implemented (previously HTC and Samsung would add the features themselves to the software). Presumably this now means Google will have added some sort of API for it. Ideally there would be a new action added so I could listen for that.

我也想知道,如果上面有可能与HTC /三星的API,如果是这样,我怎么使用它们。

I would also like to know if the above is possible with HTC/Samsung APIs and if so, how do I use them.

我一直在寻找处处为上述问题,但绝对没有运气,应用程序SecureSettings(对于塔斯克一个插件)能够挂接到HTC /三星的API,使节电反正我不是很确定他们是如何做到这一点。

I've been searching everywhere for the above questions but had absolutely no luck, the app SecureSettings (an addon for Tasker) is able to hook into the HTC/Samsung APIs to enable the power saver anyway, I'm not quite sure how they do it.

修改:节电值可以从电源管理器在Android中L为得到,不知道是否有它的行动,虽然

Edit: The power saver value can be gotten from the PowerManager in Android L, not sure if there is an Action for it though.

推荐答案

我终于想通了如何与HTC和三星的设备做到这一点。这两种存储他们的电源管理设置中Settings.System。

I've eventually figured out how to do this with HTC and Samsung devices. Both store their power manager settings in Settings.System.

HTC(侦听)使用密钥 user_powersaver_enable
三星(的Touchwiz)使用密钥 psm_switch

HTC (Sense) uses the key user_powersaver_enable. Samsung (Touchwiz) uses the key psm_switch.

这两个布尔存储为一个字符串,0是假,1为真。然后,您可以监听使用ContentObserver像这样的变化(需要API级别16或更高版本):

Both store the boolean as a String, "0" being false and "1" being true. You can then listen for changes using a ContentObserver like so (requires API level 16 or higher):

getContentResolver().registerContentObserver(Settings.System.CONTENT_URI, true, new ContentObserver(){
  @Override
  public void onChange(boolean selfChange, Uri uri){
    super.onChange(selfChange, uri);
    String key = uri.getPath();
    key = key.substring(key.lastIndexOf("/") + 1, key.length());

    if (key.equals("user_powersaver_enable") || key.equals("psm_switch")){
      boolean batterySaverEnabled = Settings.System.getString(getContentResolver(), key).equals("1");
      // do something
    }
  }
});

不过,这将只适用到Android的L是释放,当L释放HTC和三星可能会移到到AOSP电池保护程序,这意味着你将能够使用新的电池保护期L的API。

However this will only be applicable until Android L is release, when L is released HTC and Samsung will likely move over to the AOSP battery saver which means you will be able to use the new battery saver api in L.

这篇关于检查省电模式Programically的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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