如何自动连接到蓝牙设备时,在android系统的编程附近? [英] How to autoconnect to a bluetooth device when its near programmatically in android?

查看:171
本文介绍了如何自动连接到蓝牙设备时,在android系统的编程附近?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了与其它设备(不一定是一个Android)创建RFCOMM插座一个应用程序,并在其发送一些数据。现在,我可以通过套接字连接和传输数据,但我也希望能够阻止时,该设备是远远和经销商开始传递时,该设备又近了。我怎么知道,如果设备再次接近?任何指针将大大AP preciated。 :)

I am writing an app that creates RFCOMM socket with another device (not necessarily an android), and send some data over it. Right now I can connect and transfer data over the socket, but I also want to be able to stop when the device is far and auto start transfer when the device is near again. How do I know if the device is near again? Any pointers will be greatly appreciated. :)

推荐答案

我不知道一个不错的,简单的Java接口给它。您可以连接使用NDK并调用hci_read_rssi()函数(你需要写一个本地Java调用这个)。这需要你已经连接到设备上。它会给你一个信号强度读数这是相对于你的距离,你将需要调整,当然这一点。

I'm not aware of a nice, easy Java interface to it. You can connect using the NDK and call the hci_read_rssi() function (you need to write a native java call to this). This requires you to have already connected to the device. It will give you a signal strength reading which is relative to your distance, you will need to tweak this of course.

许多蓝牙设备将允许你编写他们的操作模式(参考的 http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf )。在这种模式下,您可以设置设备,无需配对这可能是你以后自动连接。当然,你是你需要使用的实际设备的限制。

Many Bluetooth devices will allow you to program their operational mode (ref http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf). In this mode you can set the device to automatically connect without the need for pairing which could be what you're after. Of course you are limited by the actual device you need to work with.

祝你好运!

这篇关于如何自动连接到蓝牙设备时,在android系统的编程附近?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆