-1
我正在創建一個應用程序,我需要顯示連接的藍牙耳機的名稱。我的耳機已打開並連接到Android設備。我將手機音頻路由到耳機,但我無法顯示連接的耳機名稱。如何在android中獲取藍牙耳機設備的信息(特別是耳機設備名稱)
我嘗試使用「getName()」方法,但它返回另一個當前未連接並關閉的已配對藍牙移動設備。
需要建議如此糟糕。
UPDATE
我用這個代碼。但不幸的是它返回當前沒有連接,我的耳機還是連接一個Android的藍牙設備名稱,我能夠路由電話音頻
bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.cancelDiscovery();
Set<BluetoothDevice> getDevices = bluetoothAdapter.getBondedDevices();
String remoteDevice = null;
for (BluetoothDevice getDevice : getDevices) {
//stringBuilder.append(getDevice);
remoteDevice = getDevice.toString();
}
blueToothDevice = bluetoothAdapter.getRemoteDevice(remoteDevice);
StringBuilder stringBuilder1 = new StringBuilder();
stringBuilder1.append(blueToothDevice.getName());
添加您的代碼。你可能會漏掉一些明顯的東西。 – 323go
用代碼 –
更新了帖子當您遍歷設備列表時,您需要查找您感興趣的設備 - 如果反覆指定remoteDevice,則只有列表中的最後一個設備將是表示。此外,查看配對設備當前是否連接也不是微不足道的;您唯一能做的就是嘗試連接並監聽連接狀態。 – 323go