3

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
Mudassir
  • 13,962
  • 8
  • 60
  • 85
  • I tried to build an app for 5.0 a couple years ago, that needed this, and I never found it :( – Nate Jul 25 '12 at 08:26
  • I think its not yet (even in BB OS 7.0) available. So if I go with my above listed approach (periodic checks), will it cause any performance issues? – Mudassir Jul 25 '12 at 08:29
  • 2
    I don't know ... but I don't see any reason why it would be a big deal. 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 :) – Nate Jul 25 '12 at 08:35
  • Nate, thanks a lot for your valuable reply, I'll really test it the way you suggested. Will you please post your comments collectively as an answer so that I can accept it :) – Mudassir Jul 25 '12 at 08:42

1 Answers1

3

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 :)

Nate
  • 30,589
  • 12
  • 76
  • 201