Build 1.0_r1(from source)

android.bluetooth
Class BluetoothHeadset

java.lang.Object
  extended by android.bluetooth.BluetoothHeadset

public class BluetoothHeadset
extends Object

The Android Bluetooth API is not finalized, and *will* change. Use at your own risk. Public API for controlling the Bluetooth Headset Service. BluetoothHeadset is a proxy object for controlling the Bluetooth Headset Service. Creating a BluetoothHeadset object will create a binding with the BluetoothHeadset service. Users of this object should call close() when they are finished with the BluetoothHeadset, so that this proxy object can unbind from the service. BlueoothHeadset objects are not guarenteed to be connected to the BluetoothHeadsetService at all times. Calls on this object while not connected to the service will result in default error return values. Even after object construction, there is a short delay (~10ms) before this proxy object is actually connected to the Service. Android only supports one connected Bluetooth Headset at a time. Note that in this context, Headset includes both Bluetooth Headset's and Handsfree devices.


Field Summary
static int RESULT_CANCELLED
          Connection cancelled before completetion.
static int RESULT_FAILURE
           
static int RESULT_SUCCESS
           
static int STATE_CONNECTED
          A headset is currently connected
static int STATE_CONNECTING
          Connection attempt in progress
static int STATE_DISCONNECTED
          No headset currently connected
static int STATE_ERROR
          There was an error trying to obtain the state
 
Constructor Summary
BluetoothHeadset(Context context)
          Create a BluetoothHeadset proxy object.
 
Method Summary
 void close()
          Close the connection to the backing service.
 boolean connectHeadset(String address, IBluetoothHeadsetCallback callback)
          Request to initiate a connection to a headset.
 boolean disconnectHeadset()
          Disconnects the current headset.
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
 String getHeadsetAddress()
          Get the Bluetooth address of the current headset.
 int getState()
          Get the current state of the Bluetooth Headset service.
 boolean isConnected(String address)
          Returns true if the specified headset is connected (does not include connecting).
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_ERROR

public static final int STATE_ERROR
There was an error trying to obtain the state

See Also:
Constant Field Values

STATE_DISCONNECTED

public static final int STATE_DISCONNECTED
No headset currently connected

See Also:
Constant Field Values

STATE_CONNECTING

public static final int STATE_CONNECTING
Connection attempt in progress

See Also:
Constant Field Values

STATE_CONNECTED

public static final int STATE_CONNECTED
A headset is currently connected

See Also:
Constant Field Values

RESULT_FAILURE

public static final int RESULT_FAILURE
See Also:
Constant Field Values

RESULT_SUCCESS

public static final int RESULT_SUCCESS
See Also:
Constant Field Values

RESULT_CANCELLED

public static final int RESULT_CANCELLED
Connection cancelled before completetion.

See Also:
Constant Field Values
Constructor Detail

BluetoothHeadset

public BluetoothHeadset(Context context)
Create a BluetoothHeadset proxy object. Remeber to call close() when you are done with this object, so that it can unbind from the BluetoothHeadsetService.

Method Detail

finalize

protected void finalize()
                 throws Throwable
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object
Throws:
Throwable - The virtual machine ignores any exceptions which are thrown during finalization.

close

public void close()
Close the connection to the backing service. Other public functions of BluetoothHeadset will return default error results once close() has been called. Multiple invocations of close() are ok.


getState

public int getState()
Get the current state of the Bluetooth Headset service.

Returns:
One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not connected to the Headset service.

getHeadsetAddress

public String getHeadsetAddress()
Get the Bluetooth address of the current headset.

Returns:
The Bluetooth address, or null if not in connected or connecting state, or if this proxy object is not connected to the Headset service.

connectHeadset

public boolean connectHeadset(String address,
                              IBluetoothHeadsetCallback callback)
Request to initiate a connection to a headset. This call does not block. Fails if a headset is already connecting or connected. Will connect to the last connected headset if address is null.

Parameters:
address - The Bluetooth Address to connect to, or null to connect to the last connected headset.
callback - A callback with onCreateBondingResult() defined, or null.
Returns:
False if there was a problem initiating the connection procedure, and your callback will not be used. True if the connection procedure was initiated, in which case your callback is guarenteed to be called.

isConnected

public boolean isConnected(String address)
Returns true if the specified headset is connected (does not include connecting). Returns false if not connected, or if this proxy object if not currently connected to the headset service.


disconnectHeadset

public boolean disconnectHeadset()
Disconnects the current headset. Currently this call blocks, it may soon be made asynchornous. Returns false if this proxy object is not currently connected to the Headset service.


Build 1.0_r1(from source)

Please submit a feedback, bug or feature