Java Code Examples for javax.bluetooth.ServiceRecord#getAttributeValue()
The following examples show how to use
javax.bluetooth.ServiceRecord#getAttributeValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceRecordSerializer.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
public static synchronized byte[] serialize(ServiceRecord record) { DataElement seq = new DataElement(DataElement.DATSEQ); int[] attrIDs = record.getAttributeIDs(); for (int i = 0; i < attrIDs.length; i++) { DataElement attrID = new DataElement(DataElement.U_INT_2, attrIDs[i]); DataElement attrValue = record.getAttributeValue(attrIDs[i]); if (attrValue != null) { seq.addElement(attrID); seq.addElement(attrValue); } } try { return des.serialize(seq); } catch (IOException e) { return null; } }
Example 2
Source File: BTServiceDiscoveryListener.java From jolie with GNU Lesser General Public License v2.1 | 5 votes |
public void servicesDiscovered( int transID, ServiceRecord[] serviceRecords ) { DataElement e; ServiceRecord r; Enumeration< DataElement > en; boolean keepRun = true; for( int i = 0; i < serviceRecords.length && keepRun; i++ ) { r = serviceRecords[ i ]; // Search for the desired UUID if( (e = r.getAttributeValue( 0x0001 )) != null ) { if( e.getDataType() == DataElement.DATSEQ ) { en = (Enumeration< DataElement >) e.getValue(); Object o; while( en.hasMoreElements() ) { o = en.nextElement().getValue(); if( o instanceof UUID ) { if( o.equals( uuid ) ) { serviceRecord = r; keepRun = false; } } } } else if( e.getDataType() == DataElement.UUID ) { if( e.getValue().equals( uuid ) ) { serviceRecord = r; keepRun = false; } } } } }
Example 3
Source File: ListServices.java From blucat with GNU General Public License v2.0 | 4 votes |
private static void printServiceRecord(ServiceRecord rec){ try{ String name = ""; if (rec.getAttributeValue(0x0100) != null) name = "" + rec.getAttributeValue(0x0100).getValue(); String desc = ""; if (rec.getAttributeValue(0x0003) != null) desc = "" + rec.getAttributeValue(0x0003).getValue(); String url = rec.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false); if (url != null) url = url.substring(0, url.indexOf(";")); String remoteMac = rec.getHostDevice().getBluetoothAddress(); String remoteName = rec.getHostDevice().getFriendlyName(false); PrintUtil.out.print("-,"); if (BlucatState.csv) PrintUtil.out.print((new Date()).getTime() + ", " + BluCatUtil.clean(remoteMac) + ", \"" + BluCatUtil.clean(remoteName) + "\", "); PrintUtil.out.println("\"" + BluCatUtil.clean(name) + "\", \"" + BluCatUtil.clean(desc) + "\", " + BluCatUtil.clean(url)); if (BlucatState.verbose){ PrintUtil.out.println(" #Attributes Returned " + rec.getAttributeIDs().length ); for (int i : rec.getAttributeIDs()){ DataElement val = rec.getAttributeValue(i); @SuppressWarnings("deprecation") String sval = val.toString(); sval = sval.replace("\n", "\n "); PrintUtil.out.println(" #" + String.format("0x%04x",i) + "=" + sval); } } }catch(Exception e){ PrintUtil.out.println("#Error: " + e.getMessage()); e.printStackTrace(); } }