FileDocCategorySizeDatePackage
Database.javaAPI DocAndroid 1.5 API7046Wed May 06 22:41:54 BST 2009android.bluetooth

Database

public final class Database extends Object
The Android Bluetooth API is not finalized, and *will* change. Use at your own risk. A low-level API to the Service Discovery Protocol (SDP) Database. Allows service records to be added to the local SDP database. Once added, these services will be advertised to remote devices when they make SDP queries on this device. Currently this API is a thin wrapper to the bluez SDP Database API. See: http://wiki.bluez.org/wiki/Database http://wiki.bluez.org/wiki/HOWTO/ManagingServiceRecords
hide

Fields Summary
private static Database
mInstance
private static final String
sLogName
Constructors Summary
private Database()
Private to enforce singleton property


             
     
        classInitNative();
    
        initializeNativeDataNative();
    
Methods Summary
public synchronized intaddServiceRecord(byte[] record)
Add a new service record.

param
record The byte[] record
return
A handle to the new record

        int handle = addServiceRecordNative(record);
        Log.i(sLogName, "Added SDP record: " + Integer.toHexString(handle));
        return handle;
    
public synchronized intaddServiceRecordFromXml(java.lang.String record)
Add a new service record, using XML.

param
record The record as an XML string
return
A handle to the new record

        int handle = addServiceRecordFromXmlNative(record);
        Log.i(sLogName, "Added SDP record: " + Integer.toHexString(handle));
        return handle;
    
private native intaddServiceRecordFromXmlNative(java.lang.String record)

private native intaddServiceRecordNative(byte[] record)

public intadvertiseRfcommService(android.bluetooth.RfcommSocket socket, java.lang.String serviceName, java.util.UUID uuid)
Advertise a service with an RfcommSocket. This adds the service the SDP Database with the following attributes set: Service Name, Protocol Descriptor List, Service Class ID List TODO: Construct a byte[] record directly, rather than via XML.

param
socket The rfcomm socket to advertise (by channel).
param
serviceName A short name for this service
param
uuid Unique identifier for this service, by which clients can search for your service
return
Handle to the new service record

        String xmlRecord =
                "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
                "<record>\n" +
                "  <attribute id=\"0x0001\">\n" + // ServiceClassIDList
                "    <sequence>\n" +
                "      <uuid value=\""
                        + uuid.toString() +       // UUID for this service
                        "\"/>\n" +
                "    </sequence>\n" +
                "  </attribute>\n" +
                "  <attribute id=\"0x0004\">\n" + // ProtocolDescriptorList
                "    <sequence>\n" +
                "      <sequence>\n" +
                "        <uuid value=\"0x0100\"/>\n" +  // L2CAP
                "      </sequence>\n" +
                "      <sequence>\n" +
                "        <uuid value=\"0x0003\"/>\n" +  // RFCOMM
                "        <uint8 value=\"" +
                        socket.getPort() +              // RFCOMM port
                        "\" name=\"channel\"/>\n" +
                "      </sequence>\n" +
                "    </sequence>\n" +
                "  </attribute>\n" +
                "  <attribute id=\"0x0100\">\n" + // ServiceName
                "    <text value=\"" + serviceName + "\"/>\n" +
                "  </attribute>\n" +
                "</record>\n";
        Log.i(sLogName, xmlRecord);
        return addServiceRecordFromXml(xmlRecord);
    
private static native voidclassInitNative()
Class load time initialization

private native voidcleanupNativeDataNative()

protected voidfinalize()

        try {
            cleanupNativeDataNative();
        } finally {
            super.finalize();
        }
    
public static synchronized android.bluetooth.DatabasegetInstance()
Singelton accessor

return
The singleton instance of Database

        if (mInstance == null) {
            mInstance = new Database();
        }
        return mInstance;
    
private native voidinitializeNativeDataNative()

public synchronized voidremoveServiceRecord(int handle)
Remove a service record. It is only possible to remove service records that were added by the current connection.

param
handle Handle to exisiting record to be removed

        try {
            removeServiceRecordNative(handle);
        } catch (IOException e) {
            Log.e(getClass().toString(), e.getMessage());
        }
    
private native voidremoveServiceRecordNative(int handle)

public synchronized voidupdateServiceRecord(int handle, byte[] record)
Update an exisiting service record.

param
handle Handle to exisiting record
param
record The updated byte[] record

        try {
            updateServiceRecordNative(handle, record);
        } catch (IOException e) {
            Log.e(getClass().toString(), e.getMessage());
        }
    
public synchronized voidupdateServiceRecordFromXml(int handle, java.lang.String record)
Update an exisiting record, using XML.

param
handle Handle to exisiting record
param
record The record as an XML string.

        try {
            updateServiceRecordFromXmlNative(handle, record);
        } catch (IOException e) {
            Log.e(getClass().toString(), e.getMessage());
        }
    
private native voidupdateServiceRecordFromXmlNative(int handle, java.lang.String record)

private native voidupdateServiceRecordNative(int handle, byte[] record)