Some one once showed me this bit of code which copes with multiple devices I have had 17 work with it.
public void startApp() {
startServer();
}
private void startServer() {
if (mServer !=null)
return;
//start the server and receiver
mServer = new Thread(this);
mServer.start();
}
Procedure run() {
if (deviceVector == null) deviceVector = new Vector();
if (agent == null) agent = local.getDiscoveryAgent();
/* Retrieve PREKNOWN devices and add them to our Vector */
RemoteDevice[] devices = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
/*
* Synchronize on vector to obtain object lock before loop.
* Else, object lock will be obtained every iteration.
*/
synchronized(deviceVector) {
for (int i = devices.length-1;i >=0;i--) {
deviceVector.addElement(devices[i]);
try {
name = devices[i].getFriendlyName(false);
}catch (IOException ioe) {
name = devices[i].getBluetoothAddress();
}
if (name.equals("")) name = devices[i].getBluetoothAddress();
knownDevices.insert(0,name,null);
}
} //End synchronized
}
}
The code is executed in its own thread
Note the synchronized(deviceVector) this locks the variable as
bluetooth does not have to wait for a lock and makes for faster updating.
This speed is neccessary as there will be lots of devices responding and in discovery mode in a short period of time.
So to summarise
devices = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
devices = agent.retrieveDevices(DiscoveryAgent.GIAC);
devices = agent.retrieveDevices(DiscoveryAgent.CACHED);
repeating the in the above code each time will obviously extend the time
of the search and allow all devices to respond.
You would the pick a remote device address and use that address for a service record profile search.
Bluetooth control panel does not have a way of increasing the amount of time to search and on phones you dont have a control panel
Jim