[英]Automatically connect to predetermined bluetooth paired device on Android
我有一个连接到蓝牙设备,打开输入/输出流和套接字并在这两个设备之间充当某种“聊天”功能的应用程序。 聊天部分和连接,一切都已完成。
但是我在这里碰壁了,我需要添加一个选项,以便当应用程序连接到蓝牙设备时,它为您提供了将其另存为默认蓝牙设备的选项,因此,当您首次打开该应用程序时,如果默认设备在范围之内,它会自动连接到该设备(该设备已配对)。
所以基本上我需要的是:我们连接到(已配对)蓝牙设备,对将其保存为默认设备回答是,现在只要打开应用程序,它就会自动寻找并连接到该设备(如果它在范围内) 。
信息来自: 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());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.