Android Bluetooth API

Android was release in version 1.0 without the Bluetooth support. The API was yanked out of the final release at the last minute. The reason was that the development team felt they didn't have the time to complete it properly and didn't want to commit to half-fast API.

Android 2.0 (SDK level 5) finally brings the official support for the Bluetooth. It is offered via android.bluetooth package.

Note that the emulator still doesn't support Bluetooth emulation. And since my Dev2/G2 is still running Android 1.5, I do not have a way to test this code and evolve it.

The main access to Bluetooth is done via the BluetoothAdapter. The adapter, returned via getDefaultAdapter() static method, offers access to various devices. The startDiscovery() method on the adapter will start the discovery of other discoverable devices. It is a synchronous call that can take some time to complete.

To get the list of all the devices that have been paired with the local device, use adapter.getBondedDevices().


package com.marakana;

import java.util.Set;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.widget.TextView;

public class BluetoothDemo extends Activity {
TextView out;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

out = (TextView) findViewById(;

// Getting the Bluetooth adapter
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
out.append("\nAdapter: " + adapter);

// Check for Bluetooth support in the first place
// Emulator doesn't support Bluetooth and will return null
if(adapter==null) {
out.append("\nBluetooth NOT supported. Aborting.");

// Starting the device discovery
out.append("\nStarting discovery...");
out.append("\nDone with discovery...");

// Listing paired devices
out.append("\nDevices Pared:");
Set<BluetoothDevice> devices = adapter.getBondedDevices();
for (BluetoothDevice device : devices) {
out.append("\nFound device: " + device);

Manifest File

Don't forget to add appropriate permissions in your manifest file:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="com.marakana" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name"
<activity android:name=".BluetoothDemo" android:label="@string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<uses-sdk android:minSdkVersion="5" />


As I mentioned before, my emulator and my physical phone do not support Bluetooth at this point, so the output just says so. I'll update this example when the support is there.

Published November 27, 2009