itziksaban
New user

Posts: 12
|
Hi guys, I am writing a bluetooth client/server j2me application. However, when the client is nokia e71, the DiscoveryAgent.searchServices does not seem to work since servicesDiscovered isn't beeing called.
here is the server code:
StreamConnectionNotifier notifier = null; StreamConnection con = null; LocalDevice localdevice = null; ServiceRecord servicerecord = null; InputStream input; String url = "btspp://localhost:63236351871240528A8EA94C3ABF2B7D;name=serialconn";
notifier = (StreamConnectionNotifier) Connector.open(url); con = notifier.acceptAndOpen(); input = con.openInputStream(); byte[] b = new byte[100]; input.read(b); String s = new String(b); stringItem.setText(s); here is the client code:
public class BTClient extends MIDlet implements DiscoveryListener {
StringItem stringItem = null; DiscoveryAgent agent = null;
public void startApp() { Form form = new Form(""); stringItem = new StringItem("", ""); Display display = Display.getDisplay(this); form.append(stringItem); display.setCurrent(form); try { agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); agent.startInquiry(DiscoveryAgent.GIAC, this); } catch (IOException ex) { ex.printStackTrace(); }
}
public BTClient(){ }
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { try { stringItem.setText(stringItem.getText() + "; " + btDevice.getFriendlyName(false)); UUID uuidSet[] = new UUID[1]; uuidSet[0] = new UUID("63236351871240528A8EA94C3ABF2B7D", false);
agent.searchServices(null, uuidSet, btDevice, this); } catch (IOException ex) { ex.printStackTrace(); } }
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { stringItem.setText(stringItem.getText() + " servicesDiscovered:"); String connectionURL = servRecord[0].getConnectionURL(0, false); try { StreamConnection con = (StreamConnection) Connector.open(connectionURL); DataOutputStream out = con.openDataOutputStream(); String s = "test test"; out.write(s.getBytes()); out.flush(); out.close(); } catch (IOException ex) { ex.printStackTrace(); }
} public void serviceSearchCompleted(int transID, int respCode) { //throw new UnsupportedOperationException("Not supported yet."); }
public void inquiryCompleted(int discType) { //stringItem.setText(stringItem.getText() + " inquiryCompleted"); } } for some reason, the servicesDiscovered is never being called when the client is e71. any ideas? does it have something to do with the null i am passing for the attrSet argument? Thanks
|