简体   繁体   English

如何检查android中其他设备的蓝牙开/关?

[英]How to check the bluetooth is ON/OFF of other devices in android?

I am working on an android app and I want to know that How i can check the status of bluetooth of other devices who are connected with my device? 我正在开发一个Android应用程序,我想知道如何检查与我的设备连接的其他设备的蓝牙状态?

When a device is connected with my device via Bluetooth then its name is saved in my phone. 当设备通过蓝牙与我的设备连接时,其名称将保存在我的手机中。 now how i can check the Bluetooth status of that paired devices in my app? 现在如何在我的应用程序中检查配对设备的蓝牙状态?

You can call BluetoothAdapter.getBondedDevices() to get the list of paired devices. 您可以调用BluetoothAdapter.getBondedDevices()以获得已配对设备的列表。

You could then attempt a connection to see if the other device is available. 然后,您可以尝试建立连接,以查看其他设备是否可用。

I suggest you the following solution: 我建议您以下解决方案:

You read some data to be sended to your application, do that once at every 1 second or more (I recommend using timertask). 您读取了一些要发送到应用程序的数据,每隔1秒或更长时间执行一次(我建议使用timertask)。

And another important thing for your application: The InputStream and Outputstream objects are final so I really don't think you can reconnect to desired device without restarting application. 对于您的应用程序来说,还有另一件重要的事情: InputStreamOutputstream对象是最终对象,所以我真的认为您不重新启动应用程序就无法重新连接到所需的设备。

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

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