File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes Bluetooth Connection Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Bluetooth Connection Problem" Watch "Bluetooth Connection Problem" New topic
Author

Bluetooth Connection Problem

sandeepg gadhvig
Greenhorn

Joined: Jul 22, 2008
Posts: 10
Hi everyone,
I am making one bluetooth application. I am able to get the devices around me.But i am not able to connect to those devices.below is some part of code.

******************commandAction of MIDlet**********************
if(d==deviceList && cmd==connect){
(new Thread(new ConnectServices(this))).start();
}
*********************ConnectServices class*********************
public class ConnectServices implements Runnable {

private HelloMIDlet midlet;
private Alert showException;

public ConnectServices(HelloMIDlet midlet){
this.midlet=midlet;
}

public void run() {

try {
for(int counter=0;counter<this.midlet.devices.size();counter++)
{ this.midlet.getDiscoveryAgent().searchServices(null,this.midlet.uuidArray,(RemoteDevice)this.midlet.devices.elementAt(counter), this.midlet);
try {Thread.sleep(1000);} catch (InterruptedException ex) {}
}
this.midlet.searchForm.append("serviceSearch DONE.");
}catch (IOException ex) {}

}
******************MIDlet code*********************************
METHOD -1
public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass device) {
devices.addElement(remoteDevice);
// other code....
}
METHOD -2
public void inquiryCompleted(int discType) { }
METHOD - 3
public void servicesDiscovered(int paramInt, ServiceRecord[] serviceRecords) {
searchForm.append("service found\nlength:"+serviceRecords.length);
/// other code....
}
METHOD-4
public void serviceSearchCompleted(int transID, int resCode) {
this.searchForm.append("serviceSearchCompleted called");
/// other code...
}
METHOD 1,2 and 4 works perfectly
BUT METHOD-3 is not even getting called.

can anyone please help me out.

Regards,
Sandeep Gadhvi.
Matthew Flint
Greenhorn

Joined: Oct 25, 2007
Posts: 14
What does "this.midlet.uuidArray" contain?
sandeepg gadhvig
Greenhorn

Joined: Jul 22, 2008
Posts: 10
public UUID[] uuidArray = new UUID[1];
uuidArray=new UUID("F0E0D0C0B0A000908070605040302010", false);
Matthew Flint
Greenhorn

Joined: Oct 25, 2007
Posts: 14
Originally posted by sandeepg gadhvig:
public UUID[] uuidArray = new UUID[1];
uuidArray=new UUID("F0E0D0C0B0A000908070605040302010", false);


OK... that UUID looks like an EchoServer UUID. Is that the service you're looking for?

Example: I have a MIDlet which connects to a bluetooth GPS device's serial port, using UUID 0x1101.

Make sure you're looking for the correct service, and that service is supported on your device. This webpage has a list of service UUIDs.

Matthew
sandeepg gadhvig
Greenhorn

Joined: Jul 22, 2008
Posts: 10
do you mean i have to you one of those hex values.
i just need to connect to simple mobile devices.
so which one should i use?
should i use OBEX? or something else?

Thank you for reply.


Regards,
Sandeep Gadhvi
Matthew Flint
Greenhorn

Joined: Oct 25, 2007
Posts: 14
Yes, you need to specify one (or more) of those hex values.

Every bluetooth device can provide a number of services: they can act as serial ports, receive files ("OBEX"), act as a network adapter, etc. Each of these services has a unique number (such as 0x1101 for the Serial Port Profile).

The value(s) you choose depends on the services/profiles supported by the device, and your reason for connecting to it!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Bluetooth Connection Problem