BluetoothServicesSearchpublic class BluetoothServicesSearch extends Object implements DiscoveryListener
Fields Summary |
---|
private DiscoveryAgent | agent | private static final UUID | L2CAP | public static final int | SERVICE_RECORD_HANDLE | public static final int | SERVICE_CLASSID_LIST | public static final int | SERVICE_RECORD_STATE | public static final int | SERVICE_ID | public static final int | PROTOCOL_DESCRIPTOR_LIST | public static final int | BROWSE_GROUP_LIST | public static final int | LANGUAGE_BASED_ATTRIBUTE_ID_LIST | public static final int | SERVICE_INFO_TIME_TO_LIVE | public static final int | SERVICE_AVAILABILITY | public static final int | BLUETOOTH_PROFILE_DESCRIPTOR_LIST | public static final int | DOCUMENTATION_URL | public static final int | CLIENT_EXECUTABLE_URL | public static final int | ICON_URL | public static final int | VERSION_NUMBER_LIST | public static final int | SERVICE_DATABASE_STATE |
Methods Summary |
---|
public void | deviceDiscovered(RemoteDevice device, DeviceClass type)
try {
System.out.println("Found " + device.getFriendlyName(false)
+ " at " + device.getBluetoothAddress());
}
catch (IOException ex) {
System.out.println("Found unnamed device "
+ " at " + device.getBluetoothAddress());
}
searchServices(device);
| public void | inquiryCompleted(int transactionID)
System.out.println("Device search " + transactionID + " complete");
| public static void | main(java.lang.String[] args)
BluetoothServicesSearch search = new BluetoothServicesSearch();
search.agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
search.agent.startInquiry(DiscoveryAgent.GIAC, search);
| private void | searchServices(RemoteDevice device)
UUID[] searchList = {L2CAP};
int[] attributes = {SERVICE_RECORD_HANDLE, SERVICE_CLASSID_LIST,
SERVICE_RECORD_STATE, SERVICE_ID,
PROTOCOL_DESCRIPTOR_LIST, BROWSE_GROUP_LIST,
LANGUAGE_BASED_ATTRIBUTE_ID_LIST,
SERVICE_INFO_TIME_TO_LIVE, SERVICE_AVAILABILITY,
BLUETOOTH_PROFILE_DESCRIPTOR_LIST, DOCUMENTATION_URL,
CLIENT_EXECUTABLE_URL, ICON_URL, VERSION_NUMBER_LIST,
SERVICE_DATABASE_STATE};
try {
System.out.println("Searching " + device.getBluetoothAddress()
+ " for services");
int trans = this.agent.searchServices(attributes, searchList, device, this);
System.out.println("Service Search " + trans + " started");
}
catch (BluetoothStateException ex) {
System.out.println( "BluetoothStateException: " + ex.getMessage() );
}
| public void | serviceSearchCompleted(int transactionID, int responseCode)
switch (responseCode) {
case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
System.out.println("Could not find device on search " + transactionID);
break;
case DiscoveryListener.SERVICE_SEARCH_ERROR:
System.out.println("Error searching device on search " + transactionID);
break;
case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:
System.out.println("No service records on device on search "
+ transactionID);
break;
case DiscoveryListener.SERVICE_SEARCH_TERMINATED:
System.out.println("User cancelled search " + transactionID);
break;
case DiscoveryListener.SERVICE_SEARCH_COMPLETED:
System.out.println("Service search " + transactionID + " complete");
break;
default:
System.out.println("Unexpected response code " + responseCode
+ " from search " + transactionID);
}
| public void | servicesDiscovered(int transactionID, ServiceRecord[] record)
for (int i = 0; i < record.length; i++) {
System.out.println("Found service " + record[i].getConnectionURL(
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false));
}
|
|