Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Separate Thread Vector

Trying to record bluetooth devices in range every 10 seconds. Store the names of each device in a vector, however, I'd like to reset the vector every reset so that I can determine the current devices in range and forget about old ones. 

 

public final class BlueListener implements DiscoveryListener {
public void run() {
try {
remoteDevices.removeAllElements();
devicesList.removeAllElements();
LocalDevice localDevice = LocalDevice.getLocalDevice();
discoveryAgent = localDevice.getDiscoveryAgent();
discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);

} catch (Exception e) {
e.printStackTrace();
}
}

public BBondBluetooth() {
run();

}

public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass cod) {
remoteDevices.addElement(remoteDevice);
}

public void onDisplay() {
founddevices.deleteAll();
if (devicesList.size() > 0) {
for (int x = 0; x < devicesList.size(); x++) {
found[x].setLabel((String) devicesList.elementAt(x));
founddevices.add(found[x]);
}
}
add(founddevices);
setTitle("Monitor: " + monitor);
}

 

By removing all elements at the start of the run() method, the onDisplay is never adding anything to the Screen. It's rather late but I'm new to the bluetooth API and would appreciate any insight, thanks all.

 

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Separate Thread Vector

and where are you adding anything to the devicesList?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Separate Thread Vector

In the public void deviceDiscovered class of BlueListener. I'll continue to work on it and inform you if I get past the issue.

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Separate Thread Vector

in the code you posted you add elements to remoteDevices, not devicesList.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Separate Thread Vector

My apologies I wasn't sure how much code to include, I also have this in the inquiryCompleted method:

 

public void inquiryCompleted(int discType) {

if (remoteDevices.size() > 0) {

// the discovery process was a success
// so let's out them in a List and display it to the user
for (int i = 0; i < remoteDevices.size(); i++) {
try {
devicesList.addElement(((RemoteDevice) remoteDevices
.elementAt(i)).getFriendlyName(true));
} catch (Exception e) {

}
}
} else {
// handle this
}
}

 

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Separate Thread Vector

the code snippets you posted did not give me any clue where the problem may be.
it may be problemativ to call "add founddevices" in onDisplay, as you do not remove it before. if it is called twice it is added twice, thus causing an illegalstateexception.

check the device log (alt+lglg) if you find anything there. add an exception breakpoint in the debugger. empty catch blocks can also disguise a lot of problems.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Separate Thread Vector

sure thing, its interesting, I never get an exception, it just doesn't work properly. After each iteration of the while loop, it should only detect the one device nearby but after several iterations it increases to three, then six detections. I just posted here in case there was something about bluetooth I was missing, I'll iron out the problem and will get to the bottom of this Smiley Happy