简体   繁体   English

在Android手机和运行OS X的笔记本电脑之间通过蓝牙发送数据

[英]Sending data via bluetooth between Android phone and laptop running OS X

It seems like a relatively mundane task to make an app that can send data via bluetooth but I've been banging my head on this for the past few days so I'm looking for any ideas. 制作一个可以通过蓝牙发送数据的应用程序似乎是一个相对平凡的任务,但是过去几天我一直在为此努力,所以我正在寻找任何想法。 I'm running OS X 10.10 and using a Nexus 5 Android device. 我正在运行OS X 10.10,并使用Nexus 5 Android设备。 Here's what I've tried so far: 到目前为止,这是我尝试过的方法:

I need a server program running on my laptop and I need a client-side android app running on my phone. 我需要在笔记本电脑上运行服务器程序,并且需要在手机上运行客户端Android应用程序。 However, (correct me if I'm wrong) the server program running on my computer needs to be able to access the Android Bluetooth API because I need to use the BluetoothServerSocket (based on the server-side code provided in Google's Android Bluetooth tutorial ). 但是,(如果我错了,请纠正我)计算机上运行的服务器程序需要能够访问Android Bluetooth API,因为我需要使用BluetoothServerSocket(基于Google的Android Bluetooth 教程中提供的服务器端代码) 。

Since it's server-side code, I need to run it on a server so I built a Java Servlet which I ran from inside Eclipse but I didn't know how to access the Android API from inside a dynamic web application. 由于它是服务器端代码,因此我需要在服务器上运行它,因此我构建了一个Java Servlet,该Java Servlet是从Eclipse内部运行的,但是我不知道如何从动态Web应用程序内部访问Android API。

So I started following this approach where the Bluecove library made that possible: http://luugiathuy.com/2011/02/android-java-bluetooth/ 因此,我开始按照这种方法在Bluecove库中实现了这一点: http ://luugiathuy.com/2011/02/android-java-bluetooth/

I tried getting Bluecove to work with OS X but there are a whole host of issues involved with that. 我尝试让Bluecove与OS X一起使用,但是与此相关的问题很多。 I found some workarounds and then got an error dealing with the IOBluetoothLocalDeviceReadSupportedFeatures device that Apple removed in its later OS versions (but Bluecove depended on it). 我找到了一些解决方法,然后在处理IOBluetoothLocalDeviceReadSupportedFeatures设备时遇到错误,该设备在其更高的OS版本中被Apple删除(但Bluecove依赖于它)。

I found a fix here that installed the old IOBluetooth library and changed the DYLD_LIBRARY_PATH to point to it. 我在这里找到了一个修复程序,该修复程序安装了旧的IOBluetooth库并更改了DYLD_LIBRARY_PATH以指向它。 Unfortunately, this had no effect (I don't know if I changed the library path properly...I followed the instructions from Solution 1 in the answer from this post). 不幸的是,这并没有影响(我不知道我是否适当地改变库路径......我跟着回答解决方案1的指示,从这个职位)。

In any event, I feel like I'm overcomplicating this task and am looking for any guidance - in terms of overall approach or a specific thing I missed. 无论如何,我觉得我要使这项任务过于繁琐,并且正在寻找任何指导-无论是总体方法还是我错过的特定事项。 The primary issue is accessing the Android Bluetooth API inside the server program intended to run on my laptop. 主要问题是访问打算在笔记本电脑上运行的服务器程序内部的Android Bluetooth API。

I eventually ended up using WiFi to send data since there was better software support for that. 我最终使用WiFi来发送数据,因为对此有了更好的软件支持。

But if someone wants to pursue the Bluetooth path, one possibility is to run OS X Lion (which had the IOBluetooth library) as a VM and run the server-side Bluecove code on the VM. 但是,如果有人想追求蓝牙路径,则一种可能性是将OS X Lion(具有IOBluetooth库)作为VM运行,并在VM上运行服务器端Bluecove代码。 This would require a separate Bluetooth USB dongle to be attached because the VM can't access the bluetooth hardware of its host machine - there may be a way but by default it can't access the in-built bluetooth hardware. 这将需要连接一个单独的蓝牙USB软件狗,因为VM无法访问其主机的蓝牙硬件-可能有一种方法,但是默认情况下它无法访问内置的蓝牙硬件。

Not an ideal solution but I don't know if there is much choice until Bluecove releases a version that is supported on recent OS versions. 这不是一个理想的解决方案,但是直到Bluecove发行了最近的OS版本支持的版本,我才知道是否有太多选择。

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

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