Is there a way to determine if the Blackberry is connected to the cable or not? (Power / USB)
I have tried several things so far ...
if(DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER > 0) { // Plugged in // TODO : Do something }else{ // Not plugged in // TODO: Do something else }
This seems to be dead code, and it doesn't work at all.
However, I was lucky 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 }
Unfortunately, it is only effective if the battery is at 100%. As soon as it falls below, it has the opposite effect.
The latter was compiled using a related problem on SO, however it does not have the desired results, as suggested there.
source share