Search code examples
blackberrybluetoothblackberry-jde

Is There Any Listener For Bluetooth Power On?


I am checking whether Bluetooth is on or not using the following method;

while (!isOn) {
    isOn = LocalDevice.isPowerOn();

    if (isOn) {
        startProcess();
        break;
    }

    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

But, I think this will eat the phone resources. I am looking for some listener kind of thing (like BroadcastReceivers in Android) which will notify me when the user turns on the Bluetooth. I've already googled it and also searched the BlackBerry Community Forum, but didn't find any solution. It will be great if anybody of you guides me in the right direction.

My development environment;

  • BlackBerry JDE Eclipse Plugin 1.5.0
  • Targeting BlackBerry JRE 5.0

Solution

  • I tried to build a Bluetooth app for OS 5.0 a couple years ago, that needed this, and I never found it available in the APIs (so I didn't build the app at all).

    The way you have your sample code, though, doesn't look terribly wasteful. A check every 10 seconds isn't a lot. The OS performs lots of other checks at a faster rate than that. The only issue I could see is if RIM implemented that one call (isPowerOn()) in some really inefficient way.

    But, really, your program is so short that I think the best thing to do is build it, let it run on your phone while you go to sleep, and then compare battery level to the next night, when you don't run the app. A good experiment is far more useful than I am :)