我在 Internet 上搜索了很长时间,但找不到我要找的东西。
如果我的设备已经连接到蓝牙设备(/在我启动我的应用程序之前),我如何通过我的应用程序找到它。
我希望有类似 bool BluetoothAdapter.isPaired();
最佳答案
如果您只对建立与任意蓝牙设备的连接感兴趣,您可以使用 BluetoothAdapter.getProfileConnectionState(profile):
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;
}
}
}
关于Android 检查蓝牙是否连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38050396/