我已经为Android和Microsoft Hololens创建了一个应用程序,可以将一些带蓝牙的GPS数据从Android手机发送到Hololens(带蓝牙LE广告商),并且可以正常工作。但是当我尝试将其他数据从Hololens发送到Android时,我遇到的问题是Android手机无法发现Hololens,尽管这些设备是配对的。甚至可以通过蓝牙从Hololens发送数据,还是我的代码中只有一些错误? Bluetooth LE Advertising是否支持双向数据传输?
答案 0 :(得分:0)
我猜你的Android应用程序中有一个BluetoothConnected线程,带有一个InputStream(我的是mmInStream)。尝试使用此作为您的'运行'线程中的函数:
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());
}
}
}