简体   繁体   English

如何等待直到蓝牙断开android

[英]how to wait till bluetooth is disconnected android

I am switching off the bluetooth on my activity finish. 我要在活动结束时关闭蓝牙。 As the calls to disconnect bluetooth are asynchronous, it is going to another activity before completely disconnecting the bluetooth. 由于断开蓝牙的调用是异步的,因此在完全断开蓝牙连接之前,它将转到另一个活动。 This behaviour is making the app to hang till the bluetooth is disconnected. 此行为使应用程序挂起,直到蓝牙断开连接。 So, I am planning to display dialog till bluetooth is disconnected. 因此,我打算显示对话框直到蓝牙断开。 Any idea on how to achieve it? 关于如何实现它的任何想法?

You should probably use a Broadcast Receiver with BluetoothDevice.ACTION_ACL_DISCONNECTED . 您可能应该将Broadcast Receiver与BluetoothDevice.ACTION_ACL_DISCONNECTED

Refer : http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_ACL_DISCONNECTED 请参阅: http : //developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_ACL_DISCONNECTED

For an example, you may refer : http://b2cloud.com.au/tutorial/listening-to-bluetooth-connections/ 例如,您可以参考: http : //b2cloud.com.au/tutorial/listening-to-bluetooth-connections/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM