2014-07-22 134 views
0

我有一个应用程序连接到蓝牙设备,打开输入/输出流和套接字,并作为某种“聊天”在这两个设备之间的功能。 聊天部分和连接,一切都完成了。自动连接到Android上预定的蓝牙配对设备

但是我在这里碰到了一堵墙,我需要添加一个选项,以便当应用程序连接到蓝牙设备时,它会提供将其保存为默认蓝牙设备的选项,因此当您第一次打开应用程序,如果默认设备在范围内,它会自动连接到它(设备已经配对)。

所以基本上我需要的是:我们连接到一个(已经配对的)蓝牙设备,我们回答是将它保存为默认设备,现在无论何时应用程序打开,它应该自动查找并连接到此设备if它在范围内。

回答

0

信息来源:http://developer.android.com/guide/topics/connectivity/bluetooth.html

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()); 
    } 
}