Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 与配对的蓝牙设备连接_Java_Android_Bluetooth - Fatal编程技术网

Java 与配对的蓝牙设备连接

Java 与配对的蓝牙设备连接,java,android,bluetooth,Java,Android,Bluetooth,我使用以下代码获取手机中所有配对设备的列表: BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); List<String> s = new ArrayList<String>(); for (Blu

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

  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();
  }
BluetoothAdapter mBluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
设置pairedDevices=mBluetoothAdapter.getBondedDevices();
列表s=新的ArrayList();
用于(蓝牙设备bt:pairedDevices){
s、 添加(bt.getName());
}
对于(int index=0;index
我有蓝牙耳机,已经配对,我希望我的应用程序通过以下方式连接到这些耳机:


你的问题是什么?它不起作用吗?您遇到的确切错误是什么?可能重复的