有人能教教我怎麼可以找出藍牙連接到其他設備(手機,耳機等)如何查看藍牙連接?
2
A
回答
4
我不知道有什麼辦法讓當前連接的設備的清單,但你可以聽使用ACL_CONNECTED意圖的新連接: http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_ACL_CONNECTED
這INTE nt在連接所在的遠程設備中包含一個額外的域。
在Android上,所有藍牙連接都是ACL連接,因此註冊此意向會爲您提供所有新連接。
所以,你的接收器將是這個樣子:
public class ReceiverBlue extends BroadcastReceiver {
public final static String CTAG = "ReceiverBlue";
public Set<BluetoothDevice> connectedDevices = new HashSet<BluetoothDevice>();
public void onReceive(Context ctx, Intent intent) {
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (BluetoothDevice.ACTION_ACL_CONNECTED.equalsIgnoreCase(action)) {
Log.v(CTAG, "We are now connected to " + device.getName());
if (!connectedDevices.contains(device))
connectedDevices.add(device);
}
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equalsIgnoreCase(action)) {
Log.v(CTAG, "We have just disconnected from " + device.getName());
connectedDevices.remove(device);
}
}
}
0
我認爲getBondedDevices()將幫助你:)
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());
}
}
謝謝:)
相關問題
- 1. Amarino藍牙連接
- 2. Java - 藍牙連接
- 3. iphone藍牙連接
- 4. 如何通過藍牙將藍牙配件連接至iPhone?
- 5. 藍牙套接字連接
- 6. 如何斷開藍牙連接(HTC Desire)
- 7. 如何發佈藍牙GATT連接
- 8. Python中的藍牙連接
- 9. 多點藍牙連接
- 10. QT4中的藍牙連接?
- 11. 藍牙插座連接
- 12. 藍牙連接問題
- 13. Android藍牙連接錯誤
- 14. Android藍牙:連接()/斷開()
- 15. 安卓連接藍牙SPP
- 16. 維護Windows藍牙連接
- 17. 多個藍牙連接
- 18. Android藍牙連接問題
- 19. iPhone藍牙連接(2題)
- 20. 保護藍牙LE連接
- 21. 藍牙連接狀態
- 22. 藍牙:沒有UUID連接
- 23. mutltiple藍牙連接連接的android
- 24. 如何防止android在藍牙設備連接時選擇藍牙A2DP路由
- 25. 如何找到連接的藍牙設備的藍牙信號強度
- 26. iOS藍牙通知應用程序藍牙設備連接時
- 27. 連接到具有藍牙地址的藍牙設備
- 28. 使用藍牙4.01連接藍牙LE設備
- 29. 將藍牙Android客戶端連接到藍牙Java服務器
- 30. Android藍牙套接字連接掛起
我試過這個。每當我連接設備它顯示「ACTION_ACL_CONNECTED」..但它立即顯示「ACTION_ACL_DISCONNECTED」..我做錯了什麼? – 2013-08-26 11:12:18
這很奇怪。這聽起來像連接只是短暫的,然後丟失。我不知道你爲什麼這樣做。 – Tom 2013-08-26 16:28:29
'在Android上,所有藍牙連接都是ACL連接'你確定嗎?有一個鏈接呢?! – Soheil 2013-09-25 18:18:28