我在互联网上搜索了很长一段时间,但我无法找到我要找的东西。
如果我的设备已经连接到蓝牙设备(/在我开始使用应用程序之前),我如何找到我的应用程序。
我希望有bool BluetoothAdapter.isPaired();
答案 0 :(得分:0)
在应用程序启动时无法检索已连接设备的列表。蓝牙API不允许您进行查询,而是允许您收听更改。
(s。This question)
答案 1 :(得分:0)
如果您只对建立与任意蓝牙设备的连接感兴趣,可以使用BluetoothAdapter.getProfileConnectionState(配置文件):
adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null && adapter.isEnabled()) {
int[] profiles = {BluetoothProfile.A2DP, BluetoothProfile.HEADSET, BluetoothProfile.HEALTH};
boolean connectionExists = false;
for (int profileId : profiles) {
if (BluetoothAdapter.getProfileConnectionState(profileId) ==
BluetoothProfile.STATE_CONNECTED) {
connectionExists = true;
break;
}
}
}