Android的蓝牙:软件导致连接中止 [英] Android Bluetooth: Software Caused Connection Abort

查看:88
本文介绍了Android的蓝牙:软件导致连接中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到例外,每当我试图与Android设备连接到bluettoth功能的设备,它连接和withina夫妇一分钟是越来越异常。 要使用BLuettoth设备(SPP配置文件),我使用的连接

I am getting exception whenever I am trying to connect with android device to bluettoth enabled device, it is connecting and withina couple of a minute it is getting exception. To connect using BLuettoth device(Spp profile), I am using

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

tmp = (BluetoothSocket) m.invoke(mmDevice, 1); 

使用这个code,我能够连接到该设备。但在这一行字节= mmInStream.read(缓冲区),我得到异常withina夫妇的分钟。我可以使用

Using this code, I am able to to connect to the device. But at this line bytes = mmInStream.read(buffer), I am getting exception withina couple of a min. I can use

if(mmInStream.available() > 0) {
bytes = mmInStream.read(buffer);
} 

但是,如果我把条件这里,它不能理解设备是否仍连接或不与其他设备。监守异常不会发生。 我无法找出解决方案,并试图为2天。但我不能找到解决办法。

But if i put the condition here, it can't understand whether device is still connected or not with other device. Becuase exception will not be occurred. I couldn't find out the solution and tried for 2 days. But I couldn't found the solution.

你能帮帮我吗?

在此先感谢

推荐答案

我有同样的问题与蓝牙播出后启动服务器。解决的办法是发送一个字节后,服务器建立通过BluetoothServerSocket.accept连接()。 BluetoothSocket.connect()一个字节后,客户端读取。所以两端处于同步

I had the same problem with a server which started after a bluetooth broadcast. The solution was to send a byte after the server established a connection via BluetoothServerSocket.accept(). The client reads after BluetoothSocket.connect() one byte. So both ends are in sync.

这篇关于Android的蓝牙:软件导致连接中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆