Một khi chúng ta đã thu được những kỷ lục dịch vụ liên quan đến dịch vụ yêu cầu của chúng tôi, chúng tôi có tất cả mọi thứ chúng ta cần phải kết nối với dịch vụ. Chúng tôi sử dụng getConnectionURL () phương pháp của các ServiceRecord để có được một String đóng gói thông tin cần thiết | 222 JAVA APIs FOR BLUETOOTH WIRELESS TECHNOLOGY Connecting to a Service Once we have obtained the service record relating to our required service we have everything we need to connect to the service. We use the getConnectionURL method of the ServiceRecord to obtain a String encapsulating the necessary information protocol Bluetooth address of device providing the service RFCOMM server channel identifier etc. to connect to the service. public String getConnectionURL int requiredSecurity boolean mustBeMaster The requiredSecurity argument specifies the level of security for the connection and can have one of three values defined in ServiceRecord public static final int NOAUTHENTICATE_NOENCRYPT public static final int AUTHENTICATE_NOENCRYPT public static final int AUTHENTICATE_ENCRYPT The mustBeMaster argument indicates whether the local device must be master in connections to this service. If false the local device is willing to be master or slave in the relationship. The master-slave role relates to the frequency hopping pattern used in RF communications between two Bluetooth devices. The master device initiates the connection and determines the frequency hopping pattern used. The slaves hop in unison to the master s pattern. The role master or slave that a device assumes relates to low-level communication and is generally irrelevant to higher level protocols. The current implementation of JSR 82 on Symbian OS supports only a value of false for the mustBeMaster parameter true will result in an exception being thrown by the open method . Once we have the connection URL we use it to open a Connection. In the case of connections using the SPP the returned object is cast as a StreamConnection as shown below. String url ServiceRecord. NOAUTHENTICATE_NOENCRYPT false StreamConnection conn StreamConnection url OutputStream output Connecting to a Service the Quick and Dirty Way In the previous .