summaryrefslogtreecommitdiffstats
path: root/docs/html/guide/topics/wireless/bluetooth.jd
diff options
context:
space:
mode:
Diffstat (limited to 'docs/html/guide/topics/wireless/bluetooth.jd')
-rw-r--r--docs/html/guide/topics/wireless/bluetooth.jd156
1 files changed, 138 insertions, 18 deletions
diff --git a/docs/html/guide/topics/wireless/bluetooth.jd b/docs/html/guide/topics/wireless/bluetooth.jd
index 0af1d2c..0567799 100644
--- a/docs/html/guide/topics/wireless/bluetooth.jd
+++ b/docs/html/guide/topics/wireless/bluetooth.jd
@@ -29,6 +29,7 @@ other devices</li>
<li><a href="#Profiles">Working with Profiles</a>
<ol>
<li><a href="#AT-Commands">Vendor-specific AT commands</a>
+ <li><a href="#HDP">Health Device Profile</a>
</ol></li>
</ol>
@@ -43,6 +44,7 @@ other devices</li>
<h2>Related samples</h2>
<ol>
<li><a href="{@docRoot}resources/samples/BluetoothChat/index.html">Bluetooth Chat</a></li>
+ <li><a href="{@docRoot}resources/samples/BluetoothHDP/index.html">Bluetooth HDP (Health Device Profile)</a></li>
</ol>
</div>
@@ -132,11 +134,27 @@ Headset and Hands-Free (v1.5) profiles.</dd>
audio can be streamed from one device to another over a Bluetooth connection.
"A2DP" stands for Advanced Audio Distribution Profile.</dd>
-<dt>{@link android.bluetooth.BluetoothProfile.ServiceListener}</dt>
+<dt>{@link android.bluetooth.BluetoothHealth}</dt>
+<dd> Represents a Health Device Profile proxy that controls the Bluetooth service.</dd>
+
+<dt>{@link android.bluetooth.BluetoothHealthCallback}</dt>
+
+<dd>An abstract class that you use to implement {@link
+android.bluetooth.BluetoothHealth} callbacks. You must extend this class and
+implement the callback methods to receive updates about changes in the
+application’s registration state and Bluetooth channel state.</dd>
+
+<dt>{@link android.bluetooth.BluetoothHealthAppConfiguration}</dt>
+
+<dd>Represents an application configuration that the Bluetooth Health third-party
+application registers to communicate with a remote Bluetooth health
+device.</dd>
+
+<dt>{@link android.bluetooth.BluetoothProfile.ServiceListener}</dt>
<dd>An interface that notifies {@link android.bluetooth.BluetoothProfile} IPC
clients when they have been connected to or disconnected from the service (that
-is, the internal service that runs a particular profile). </dd>
+is, the internal service that runs a particular profile). </dd>
</dl>
@@ -231,12 +249,20 @@ if (!mBluetoothAdapter.isEnabled()) {
<p>A dialog will appear requesting user permission to enable Bluetooth, as shown
in Figure 1. If the user responds "Yes," the system will begin to enable Bluetooth
and focus will return to your application once the process completes (or fails).</p>
-<p>If enabling Bluetooth succeeds, your Activity will receive the {@link
+
+<p>The {@code REQUEST_ENABLE_BT} constant passed to {@link
+android.app.Activity#startActivityForResult(Intent,int) startActivityForResult()} is a locally
+defined integer (which must be greater than 0), that the system passes back to you in your
+{@link
+android.app.Activity#onActivityResult(int,int,Intent) onActivityResult()} implementation as the
+<code>requestCode</code> parameter.</p>
+
+<p>If enabling Bluetooth succeeds, your activity receives the {@link
android.app.Activity#RESULT_OK} result code in the {@link
android.app.Activity#onActivityResult(int,int,Intent) onActivityResult()}
callback. If Bluetooth was not enabled
-due to an error (or the user responded "No") then the result code will be {@link
-android.app.Activity#RESULT_CANCELED}.</p>
+due to an error (or the user responded "No") then the result code is {@link
+android.app.Activity#RESULT_CANCELED}.</p>
</li>
</ol>
@@ -413,11 +439,11 @@ startActivity(discoverableIntent);
<p>A dialog will be displayed, requesting user permission to make the device
discoverable, as shown in Figure 2. If the user responds "Yes," then the device
-will become discoverable for the specified amount of time. Your Activity will
+will become discoverable for the specified amount of time. Your activity will
then receive a call to the {@link android.app.Activity#onActivityResult(int,int,Intent)
onActivityResult())} callback, with the result code equal to the duration that the device
is discoverable. If the user responded "No" or if an error occurred, the result code will
-be Activity.RESULT_CANCELLED.</p>
+be {@link android.app.Activity#RESULT_CANCELED}.</p>
<p class="note"><strong>Note:</strong> If Bluetooth has not been enabled on the device,
then enabling device discoverability will automatically enable Bluetooth.</p>
@@ -550,7 +576,7 @@ socket.</p>
</ol>
<p>The {@link android.bluetooth.BluetoothServerSocket#accept()} call should not
-be executed in the main Activity UI thread because it is a blocking call and
+be executed in the main activity UI thread because it is a blocking call and
will prevent any other interaction with the application. It usually makes
sense to do all work with a {@link android.bluetooth.BluetoothServerSocket} or {@link
android.bluetooth.BluetoothSocket} in a new
@@ -678,7 +704,7 @@ android.bluetooth.BluetoothSocket#connect()} method times out (after about
12 seconds), then it will throw an exception.</p>
<p>Because {@link
android.bluetooth.BluetoothSocket#connect()} is a blocking call, this connection
-procedure should always be performed in a thread separate from the main Activity
+procedure should always be performed in a thread separate from the main activity
thread.</p>
<p class="note">Note: You should always ensure that the device is not performing
device discovery when you call {@link
@@ -820,7 +846,7 @@ private class ConnectedThread extends Thread {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
- // Send the obtained bytes to the UI Activity
+ // Send the obtained bytes to the UI activity
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
@@ -829,14 +855,14 @@ private class ConnectedThread extends Thread {
}
}
- /* Call this from the main Activity to send data to the remote device */
+ /* Call this from the main activity to send data to the remote device */
public void write(byte[] bytes) {
try {
mmOutStream.write(bytes);
} catch (IOException e) { }
}
- /* Call this from the main Activity to shutdown the connection */
+ /* Call this from the main activity to shutdown the connection */
public void cancel() {
try {
mmSocket.close();
@@ -848,12 +874,12 @@ private class ConnectedThread extends Thread {
<p>The constructor acquires the necessary streams and once executed, the thread
will wait for data to come through the InputStream. When {@link
java.io.InputStream#read(byte[])} returns with
-bytes from the stream, the data is sent to the main Activity using a member
+bytes from the stream, the data is sent to the main activity using a member
Handler from the parent class. Then it goes back and waits for more bytes from
the stream.</p>
<p>Sending outgoing data is as simple as calling the thread's
-<code>write()</code> method from the main Activity and passing in the bytes to
+<code>write()</code> method from the main activity and passing in the bytes to
be sent. This method then simply calls {@link
java.io.OutputStream#write(byte[])} to send the data to the remote device.</p>
@@ -889,7 +915,7 @@ Bluetooth Headset Service via interprocess communication (<a
href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#IPC">IPC</a
>). This includes both Bluetooth Headset and Hands-Free (v1.5) profiles. The
{@link android.bluetooth.BluetoothHeadset} class includes support for AT commands.
-For more discussion of this topic, see <a href="#AT-Commands">Vendor-specific AT commands</a></li>
+For more discussion of this topic, see <a href="#AT-Commands">Vendor-specific AT commands</a></li>
<li><strong>A2DP</strong>. The Advanced Audio Distribution Profile (A2DP)
profile defines how high quality audio can be streamed from one device to
@@ -897,13 +923,25 @@ another over a Bluetooth connection. Android provides the {@link
android.bluetooth.BluetoothA2dp} class, which is a proxy for controlling
the Bluetooth A2DP Service via IPC.</li>
+ <li><strong>Health Device</strong>. Android 4.0 (API level 14) introduces
+support for the Bluetooth Health Device Profile (HDP). This lets you create
+applications that use Bluetooth to communicate with health devices that support
+Bluetooth, such as heart-rate monitors, blood meters, thermometers, scales, and
+so on. For a list of supported devices and their corresponding device data
+specialization codes, refer to <strong>Bluetooth Assigned Numbers</strong> at <a
+href="http://www.bluetooth.org">www.bluetooth.org</a>. Note that these values
+are also referenced in the ISO/IEEE 11073-20601 [7] specification as
+MDC_DEV_SPEC_PROFILE_* in the Nomenclature Codes Annex. For more discussion of
+HDP, see <a href="#HDP">Health Device Profile</a>.</li>
+
</ul>
<p>Here are the basic steps for working with a profile:</p>
<ol>
- <li>Get the default adapter, as described in <a href="{@docRoot}guide/topics/wireless/bluetooth.
-html#SettingUp">Setting Up Bluetooth</a>.</li>
+ <li>Get the default adapter, as described in
+ <a href="{@docRoot}guide/topics/wireless/bluetooth.html#SettingUp">Setting Up
+ Bluetooth</a>.</li>
<li>Use {@link
android.bluetooth.BluetoothAdapter#getProfileProxy(android.content.Context,
@@ -925,7 +963,9 @@ to the profile proxy object.</li>
state of the connection and perform other operations that are relevant to that
profile.</li>
</ol>
-<p> For example, this code snippet shows how to connect to a {@link android.bluetooth.BluetoothHeadset} proxy object so that you can control the
+
+<p> For example, this code snippet shows how to connect to a {@link
+android.bluetooth.BluetoothHeadset} proxy object so that you can control the
Headset profile:</p>
<pre>BluetoothHeadset mBluetoothHeadset;
@@ -955,6 +995,8 @@ private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile
mBluetoothAdapter.closeProfileProxy(mBluetoothHeadset);
</pre>
+
+
<h3 id="AT-Commands">Vendor-specific AT commands</h3>
<p>Starting in Android 3.0, applications can register to receive system
@@ -964,3 +1006,81 @@ broadcasts that indicate a connected device's battery level and could notify the
user or take other action as needed. Create a broadcast receiver for the {@link
android.bluetooth.BluetoothHeadset#ACTION_VENDOR_SPECIFIC_HEADSET_EVENT} intent
to handle vendor-specific AT commands for the headset.</p>
+
+<h3 id="HDP">Health Device Profile</h3>
+
+<p>Android 4.0 (API level 14) introduces support for the Bluetooth Health Device
+Profile (HDP). This lets you create applications that use Bluetooth to
+communicate with health devices that support Bluetooth, such as heart-rate
+monitors, blood meters, thermometers, and scales. The Bluetooth Health API
+includes the classes {@link android.bluetooth.BluetoothHealth}, {@link
+android.bluetooth.BluetoothHealthCallback}, and {@link
+android.bluetooth.BluetoothHealthAppConfiguration}, which are described in <a
+href="#TheBasics">The Basics</a>. </p>
+
+<p>In using the Bluetooth Health API, it's helpful to understand these key HDP concepts:</p>
+<table>
+ <tr>
+ <th>Concept</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><strong>Source</strong></td>
+
+ <td>A role defined in HDP. A <em>source</em> is a health device that
+transmits medical data (weight scale, glucose meter, thermometer, etc.) to a
+smart device such as an Android phone or tablet. </td>
+ </tr>
+ <tr>
+ <td><strong>Sink</strong></td>
+
+ <td>A role defined in HDP. In HDP, a <em>sink</em> is the smart device that
+receives the medical data. In an Android HDP application, the sink is
+represented by a {@link android.bluetooth.BluetoothHealthAppConfiguration}
+object.</td>
+ </tr>
+ <tr>
+ <td><strong>Registration</strong></td>
+ <td>Refers to registering a sink for a particular health device.</td>
+ </tr>
+ <tr>
+ <td><strong>Connection</strong></td>
+
+ <td>Refers to opening a channel between a health device and a smart device
+such as an Android phone or tablet.</td>
+ </tr>
+</table>
+
+<h4>Creating an HDP Application</h4>
+
+<p>Here are the basic steps involved in creating an Android HDP application:</p>
+<ol>
+
+ <li>Get a reference to the {@link android.bluetooth.BluetoothHealth} proxy
+object. <p>Similar to regular headset and A2DP profile devices, you must call
+{@link android.bluetooth.BluetoothAdapter#getProfileProxy getProfileProxy()}
+with a {@link android.bluetooth.BluetoothProfile.ServiceListener} and the {@link
+android.bluetooth.BluetoothProfile.ServiceListener#HEALTH} profile type to
+establish a connection with the profile proxy object.</p> </li>
+
+ <li>Create a {@link android.bluetooth.BluetoothHealthCallback} and register an
+application configuration
+({@link android.bluetooth.BluetoothHealthAppConfiguration})
+that acts as a health
+sink.</li>
+
+ <li>Establish a connection to a health device. Some devices will initiate the
+connection. It is unnecessary to carry out this step for those devices.</li>
+
+ <li>When connected successfully to a health device, read/write to the health
+device using the file descriptor. <p>The received data needs to be interpreted
+using a health manager which implements the IEEE 11073-xxxxx
+specifications.</p></li>
+
+ <li>When done, close the health channel and unregister the application. The
+channel also closes when there is extended inactivity.</li>
+</ol>
+
+<p>For a complete code sample that illustrates these steps, see <a
+href="{@docRoot}resources/samples/BluetoothHDP/index.html">Bluetooth HDP (Health
+Device Profile)</a>. </p>