• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bluetooth Connection Problem

 
sandeepg gadhvig
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "this.midlet.uuidArray" contain?
 
sandeepg gadhvig
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public UUID[] uuidArray = new UUID[1];
uuidArray=new UUID("F0E0D0C0B0A000908070605040302010", false);
 
Matthew Flint
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic