java - 与配对的蓝牙设备连接
问题描述
我使用以下代码获取手机中所有已配对设备的列表:
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();
}
我有已经配对的蓝牙耳机,我希望我的应用程序以这种方式连接到这些耳机:
解决方案
推荐阅读
- python - Python,MySQL - + 不支持的操作数类型:'int' 和 'str'
- javascript - MatDialog 已经打开时如何更改它的 maxWidth?
- javascript - 如何使用 ramda 或不使用 ramda 来规范化这个对象:
- python - psycopg2 没有从 postgresql 数据库中读取/获取带有完整小数的精确浮点值
- node.js - 我无法使用 MongoDB 和 Node 填充数据
- javascript - 替换方法在 React 组件中未按预期工作
- android - 带有微调器样式的 Materialdatepicker
- preflight - 在本地运行时观察到飞行前请求,但在生产中没有?
- typescript - '{ useNewUrlParser: boolean; 类型的参数 useUnifiedTopology: boolean}' 不可分配给参数类型'
- cuda - 如何在头文件上使用带有 CUDA 的 clangd 文本突出显示