黑莓确定是否使用外部电源 [英] Blackberry determine if using external power

查看:314
本文介绍了黑莓确定是否使用外部电源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,以确定是否黑莓已经电缆插入或不? (电源/ USB)

Is there a way to determine whether or not the Blackberry has a cable plugged in or not? (power/USB)

我已经尝试了一些东西至今...

I have tried a number of things so far...

if(DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER > 0)
{
// Plugged in
// TODO : Do something
}else{
// Not plugged in
// TODO: Do something else
}

的else显然是死code,这并不在所有的工作。

The else is apparently dead code, and this doesn't work at all.

不过我有一些运气以下内容:

I have however had some luck with the following:

if((DeviceInfo.getBatteryStatus() ^ DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER) != 0)
{
    // Plugged in
    // TODO : Do something
}else{
    // Plugged in
    // TODO : Do something else
}

不幸的是,虽然,它是如果电池为100%才有效。只要它下面下降,它具有相反的效果。

Sadly though, it is only effective if the battery is at 100%. As soon as it drops below, it has the opposite effect.

后者是使用<编译href=\"http://stackoverflow.com/questions/1266449/checking-battery-status-in-blackberry-development\">related发出在SO,但是它不具有所期望的结果的建议有

The latter was compiled using a related issue on SO, however it does not have the desired results as suggested there.

推荐答案

这是我在过去的习惯:

    private boolean isBatteryCharging(){
        int battst = DeviceInfo.getBatteryStatus();
        if(((battst & DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER) != 0) 
            || ((battst & DeviceInfo.BSTAT_CHARGING) != 0) 
            || ((battst & DeviceInfo.BSTAT_AC_CONTACTS) != 0)){
            return true;
        }
        return false;       
    }

希望它帮助。

这篇关于黑莓确定是否使用外部电源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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