Android蓝牙:软件导致连接中断

Android蓝牙:软件导致连接中断,android,bluetooth,Android,Bluetooth,每当我尝试将android设备连接到启用BlueToth的设备时,我都会遇到异常,它正在连接,几分钟后就会出现异常。 要使用BLuettoth设备(Spp配置文件)进行连接,我使用 Method m; m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); tmp = (BluetoothSocket) m.invoke(mmDevice, 1); 使用此代码,我可以连接到设备。

每当我尝试将android设备连接到启用BlueToth的设备时,我都会遇到异常,它正在连接,几分钟后就会出现异常。 要使用BLuettoth设备(Spp配置文件)进行连接,我使用

Method m;
m = mmDevice.getClass().getMethod("createRfcommSocket",
new Class[] { int.class });

tmp = (BluetoothSocket) m.invoke(mmDevice, 1); 
使用此代码,我可以连接到设备。但在这一行bytes=mmInStream.read(buffer),我在几分钟内得到异常。我可以使用

if(mmInStream.available() > 0) {
bytes = mmInStream.read(buffer);
} 
但如果我把条件放在这里,它就无法理解设备是否仍然与其他设备连接。因为不会发生异常。 我找不到解决方案,试了两天。但我找不到解决办法

你能帮帮我吗


提前感谢

我在蓝牙广播后启动的服务器上遇到了同样的问题。解决方案是在服务器通过BluetoothServerSocket.accept()建立连接后发送一个字节。客户端读取BluetoothSocket.connect()后的一个字节。所以两端都是同步的。

我在蓝牙广播后启动的服务器上遇到了同样的问题。解决方案是在服务器通过BluetoothServerSocket.accept()建立连接后发送一个字节。客户端读取BluetoothSocket.connect()后的一个字节。所以两端都是同步的。

可能的重复