Get all Blue tooth devices Connected - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

Get all Blue tooth devices Connected

Demo Code


//package com.java2s;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

import java.util.Set;

public class Main {
    /**/*from w ww  .jav a2 s  .co m*/
     * Get all Blue tooth devices Connected -
     * This is identical to the function in schasStrings.getBluetoothDevices
     * @return
     */
    public static String getBluetoothDevices() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

        String BTlist = "Bluetooth Devices: \n";
        if (adapter != null && adapter.isEnabled()) {
            Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
            if (pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {
                    if (device.getName() != null) {
                        BTlist += device.getName() + "  "
                                + device.getAddress() + "\n";
                    }
                }
            }
            BTlist += "End of Bluetooth Devices";
        } else {
            BTlist = "Bluetooth not connected";
        }
        return BTlist;
    }
}

Related Tutorials