get Bluetooth Device - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

get Bluetooth Device

Demo Code


//package com.java2s;

import java.util.Set;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

public class Main {

    public static Set<BluetoothDevice> getBluetoothDevice() {
        if (isThisMahionSupportBluetooth() && isBluetoothHadOpen()) {
            BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
            Set<BluetoothDevice> device = ba.getBondedDevices();
            if (device.size() > 0) {
                for (BluetoothDevice bd : device) {
                    System.out.println(bd.getAddress() + bd.getName());
                }//from ww  w. j av  a  2 s.c  om
            }
            return device;
        }
        return null;
    }

    public static boolean isThisMahionSupportBluetooth() {
        BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
        if (null != ba) {
            return true;
        }
        return false;
    }

    public static boolean isBluetoothHadOpen() {
        if (isThisMahionSupportBluetooth()) {
            BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
            if (ba.isEnabled()) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials