Find Bluetooth device by name - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

Find Bluetooth device by name

Demo Code


//package com.java2s;

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

import java.util.Set;

public class Main {

    public static BluetoothDevice findBT(String name) {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

        if (adapter == null) {
            return null;
        }//  w w w  . j a  va  2s. c  o m

        Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
        if (pairedDevices.size() > 0) {
            for (BluetoothDevice device : pairedDevices) {
                if (device.getName().contains(name)) {
                    return device;
                }
            }
        }
        return null;
    }
}

Related Tutorials