Example usage for android.bluetooth BluetoothAdapter getBondedDevices

List of usage examples for android.bluetooth BluetoothAdapter getBondedDevices

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter getBondedDevices.

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH)
public Set<BluetoothDevice> getBondedDevices() 

Source Link

Document

Return the set of BluetoothDevice objects that are bonded (paired) to the local adapter.

Usage

From source file:Main.java

public static boolean getBluetoothIsConn() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter.getBondedDevices().size() > 0)
        return true;
    return false;
}

From source file:Main.java

public static Set<BluetoothDevice> getPairedBluetoothDevices() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    return bluetoothAdapter.getBondedDevices();
}

From source file:Main.java

public static BluetoothDevice getDeviceByAddress(String address) {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    for (BluetoothDevice device : mBluetoothAdapter.getBondedDevices()) {
        if (device.getAddress().equals(address)) {
            return device;
        }/*  ww  w  . j a  v a2s. c  om*/
    }

    return null;
}

From source file:Main.java

public static Set<BluetoothDevice> findPaired() {

    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();

    if (devices == null || devices.isEmpty()) {
        return null;

    } else {//w  w w.j  a va  2 s.c  om
        return devices;
    }

}

From source file:Main.java

public static final String[] getBondedDeviceNames() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    Set<BluetoothDevice> devices = adapter.getBondedDevices();
    String[] names = new String[devices.size()];

    int i = 0;/* w  w  w.  j a  va  2 s  .c om*/
    for (BluetoothDevice d : devices) {
        Log.d(TAG, "Found bonded device " + d.getName());
        names[i++] = d.getName();
    }

    return names;
}

From source file:Main.java

public static BluetoothDevice getDevice(BluetoothAdapter bluetoothAdapter) {
    BluetoothDevice innerprinter_device = null;
    Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
    for (BluetoothDevice device : devices) {
        if (device.getAddress().equals(Innerprinter_Address)) {
            innerprinter_device = device;
            break;
        }// w  ww . java  2  s .  c  om
    }
    return innerprinter_device;
}

From source file:Main.java

public static void unpairMac(String macToRemove) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
    try {/*w w  w. ja  v a 2s  .  c o  m*/
        Class<?> btDeviceInstance = Class.forName(BluetoothDevice.class.getCanonicalName());
        Method removeBondMethod = btDeviceInstance.getMethod("removeBond");
        boolean cleared = false;
        for (BluetoothDevice bluetoothDevice : bondedDevices) {
            String mac = bluetoothDevice.getAddress();
            if (mac.equals(macToRemove)) {
                removeBondMethod.invoke(bluetoothDevice);
                Log.i(TAG, "Cleared Pairing");
                cleared = true;
                break;
            }
        }

        if (!cleared) {
            Log.i(TAG, "Not Paired");
        }
    } catch (Throwable th) {
        Log.e(TAG, "Error pairing", th);
    }
}

From source file:Main.java

/**
 * Populates the device names and the device addresses with all the suitable
 * bluetooth devices.//from  ww  w .  j  a  va2s .  c om
 * 
 * @param bluetoothAdapter the bluetooth adapter
 * @param deviceNames list of device names
 * @param deviceAddresses list of device addresses
 */
public static void populateDeviceLists(BluetoothAdapter bluetoothAdapter, List<String> deviceNames,
        List<String> deviceAddresses) {
    // Ensure the bluetooth adapter is not in discovery mode.
    bluetoothAdapter.cancelDiscovery();

    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    for (BluetoothDevice device : pairedDevices) {
        BluetoothClass bluetoothClass = device.getBluetoothClass();
        if (bluetoothClass != null) {
            // Not really sure what we want, but I know what we don't want.
            switch (bluetoothClass.getMajorDeviceClass()) {
            case BluetoothClass.Device.Major.COMPUTER:
            case BluetoothClass.Device.Major.PHONE:
                break;
            default:
                deviceAddresses.add(device.getAddress());
                deviceNames.add(device.getName());
            }
        }
    }
}

From source file:com.quadmeup.smartporttelemetrer.activity.BluetoothSelectActivity.java

private void fillDeviceList() {
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();

    ArrayList<BluetoothDevice> list = new ArrayList<>();
    list.addAll(bluetoothAdapter.getBondedDevices());

    listAdapter.setData(list);//from  w w  w .ja v a2  s .c  o m
    listAdapter.notifyDataSetChanged();
}

From source file:com.example.multi_ndef.frag_bt.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_bt, container, false);

    btSpinner = (Spinner) v.findViewById(R.id.spinnerbt);
    btSpinner.setOnItemSelectedListener(this);
    ma = (CNFCInterface) getActivity().getApplication();
    try {/* w  w  w .  ja  v  a 2 s.c o  m*/
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();

        if (pairedDevices.size() > 0) {
            for (BluetoothDevice device : pairedDevices) {
                String deviceBTName = device.getName();
                String address = device.getAddress();
                //String deviceBTMajorClass = getBTMajorDeviceClass(device.getBluetoothClass().getMajorDeviceClass());
                SpinnerArrayBT_Device_name.add(deviceBTName);
                SpinnerArrayBT_devices_mac.add(address);
            }
        }
    } catch (Exception e)
    //SpinnerArrayBT.a
    {

        Toast toast = Toast.makeText(getActivity().getApplicationContext(), "Bluetooth Code Error",
                Toast.LENGTH_SHORT);
        toast.show();

        int a1 = 10;
    }

    ArrayAdapter<String> btArrayAdapter = new ArrayAdapter<String>(this.getActivity(),
            android.R.layout.simple_spinner_item, SpinnerArrayBT_Device_name);
    btArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    btSpinner.setAdapter(btArrayAdapter);

    return v;
}