catch (BluetoothStateException e) {
e.printStackTrace();
return null;
}
String url = "btl2cap://" + localDev.getBluetoothAddress() + ":";
DataElement protocolDescriptorListElement = (DataElement)attributes.get(new Integer(4));
if (protocolDescriptorListElement == null)
throw new IllegalArgumentException("Service Record is not propperly populated. Protocol Descriptor is missing.");
Enumeration protocolDescriptorList = (Enumeration)protocolDescriptorListElement.getValue();
while (protocolDescriptorList.hasMoreElements()) {
DataElement protocolDescriptorElement = (DataElement)protocolDescriptorList.nextElement();
if (protocolDescriptorElement == null)
throw new IllegalArgumentException("Service Record is not propperly populated. Protocol Descriptor is missing.");
Enumeration protocolParameterList = (Enumeration)protocolDescriptorElement.getValue();
if (protocolParameterList.hasMoreElements()) {
DataElement protocolDescriptor = (DataElement)protocolParameterList.nextElement();
if (protocolDescriptor != null) {
if (protocolDescriptor.getDataType() == DataElement.UUID) {
UUID protocolDescriptorUUID = (UUID)protocolDescriptor.getValue();
if (protocolDescriptorUUID.toLong() == 0x0100) //is L2CAP
{
if (protocolParameterList.hasMoreElements()) {
DataElement protocolPSMElement = (DataElement)protocolParameterList.nextElement();
{
if (protocolPSMElement != null) {
if (protocolPSMElement.getDataType() == DataElement.UUID) {
UUID psm = (UUID)protocolPSMElement.getValue();
url += psm.toString() + ";";
break;
}
}
}
}
}
else //is not L2CAP
{
url += protocolDescriptorUUID.toString() + ";";
while (protocolParameterList.hasMoreElements()) {
DataElement parameter = (DataElement)protocolParameterList.nextElement();
url += parameter.toString() + ";";
}
break;
}
}
}