try {
ServiceRecord serviceRecord = (ServiceRecord) listener.getServices().get(listener.getDevices().get(0))[0];
if(serviceRecord == null) {
System.out.println("The connection could not be made. Device not discovered");
} else {
String url = serviceRecord.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if(url == null) {
System.out.println("The connection could not be made. Connection url not found");
} else {
Connection connection = Connector.open(url);
if(connection instanceof StreamConnectionNotifier) {
streamConnNotifier = (StreamConnectionNotifier)connection;
streamConnection = streamConnNotifier.acceptAndOpen();
} else if(connection instanceof StreamConnection) {
streamConnNotifier = null;
streamConnection = (StreamConnection)connection;
} else {
throw new Exception("Connection class not known. " + connection.getClass().getCanonicalName());
}
System.out.println("aqui");
//read string from spp client
Input = streamConnection.openInputStream();
Output = streamConnection.openOutputStream();
retvalue = true;
}
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("The connection could not be made." + e.getMessage());
}