我已经为Android和Microsoft Hololens创建了一个应用程序,在那里可以通过蓝牙将一些GPS数据从Android手机发送到Hololens (带有蓝牙广告),而且工作正常。但是,当我试图从Hololens向Android发送其他数据时,我遇到了一个问题,Android手机无法发现Hololens,尽管这些设备是配对的。有没有可能用蓝牙从Hololens发送数据,或者只是我的代码有问题?蓝牙LE广告是否支持双向数据传输?
发布于 2017-03-21 22:50:41
我猜你的安卓应用程序中有一个带有InputStream的BluetoothConnected线程(我的是mmInStream)。尝试将此函数用作线程中的“run”函数:
public void run() {
System.out.println("BT THREAD RUNNING");
mmBuffer = new byte[1024];
int numBytes; // bytes returned from read()
InputStreamReader mmInStreamReader = new InputStreamReader(mmInStream);
BufferedReader mmReader = new BufferedReader(mmInStreamReader);
// Keep listening to the InputStream until an exception occurs.
while (true) {
try {
// Read from the InputStream.
Thread.sleep(100);
String s = mmReader.readLine();
Thread.sleep(100);
//Static class that handles the response
BluetoothCommunications.responseHandler(s);
} catch (IOException e) {
System.out.println("Input stream was disconnected" + e);
main.disconnected();
break;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}https://stackoverflow.com/questions/42929071
复制相似问题