首页 > 解决方案 > 与配对的蓝牙设备连接

问题描述

我使用以下代码获取手机中所有已配对设备的列表:

  BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

  List<String> s = new ArrayList<String>();
  for (BluetoothDevice bt : pairedDevices) {
      s.add(bt.getName());
  }

  for (int index = 0; index < s.size(); index++) {
      Toast.makeText(this, "Device Name: " + s.get(index), Toast.LENGTH_SHORT).show();
  }

我有已经配对的蓝牙耳机,我希望我的应用程序以这种方式连接到这些耳机:

这样

标签: javaandroidbluetooth

解决方案


推荐阅读