如何在Android中实现修复蓝牙设备
我想编写一个无需任何发现/扫描的蓝牙应用程序。 为此,我想对客户端需要在代码中连接的服务器设备进行硬编码。
如果我使用此构造函数:
public ConnectThread(BluetoothDevice device) {
我必须如何实现该设备?使用 MAC 地址变量?
如果我尝试这样的操作:
device = new BluetoothDevice("XX:XX:XX:XX:XX:XX");
Eclipse 说:“构造函数不可见
”
I want to write a Bluetooth app without any discovery/scanning.
For that I want to hardcode the server device, which the client needs to connect in the code.
If I use this constructor:
public ConnectThread(BluetoothDevice device) {
How do I have to implement the device? With a variable of the MAC Address?
If I try something like this:
device = new BluetoothDevice("XX:XX:XX:XX:XX:XX");
Eclipse says: "constructor not visible
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用BluetoothAdapter.getRemoteDevice(String) 创建代表已知蓝牙设备地址的设备的BluetoothDevice。
You can use BluetoothAdapter.getRemoteDevice(String) to create a BluetoothDevice representing a device of a known Bluetooth Device Address.
您可以按照@Dennis Mathews 所说的进行操作,但是设备必须先进行配对,然后才能在它们之间发送数据。这意味着您的每个客户端设备都必须提前与您的单个服务器设备配对。即使对于客户端蓝牙套接字也是如此,至少在我在运行 Android 2.2 的 Captivate 上进行的测试中是如此。
You can do as @Dennis Mathews says, however the devices must be paired before you can send data between them. That means that each of your client devices has to have already paired with your single server device ahead of time. This is true even for client bluetooth sockets, at least in my testing on a Captivate running Android 2.2.