http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html android.bluetooth.BluetoothAdapter 可以找到已绑定的蓝牙。Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } }
android.bluetooth.BluetoothAdapter
可以找到已绑定的蓝牙。Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices
if (pairedDevices.size() > 0) {
// Loop through paired devices
for (BluetoothDevice device : pairedDevices) {
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
}
你好,这个是已绑定的设备,而非已连接的设备,
我现在是用你说的这种方法通过getName来连接设备,
但如果有名字相同的设备则无法判断出已连接的设备进而直接连接
但纠结的是,程序中无法获取该状态
这里有一个方法,但是要绑定系统对应服务
所以他是异步的,必须首先保证已经绑定了服务才能准确查询
记着蓝牙权限的添加