Bluetooth Android手机正在收听蓝牙连接,但蓝牙设备无法连接
这里的设备是欧姆龙蓝牙血压监测仪708-BT 健康设备已经与运行安卓4.0.3的HTC Sensation配对 健康设备启动连接,我的Android应用程序应该会接受它。应用程序设置为目标API级别16,最低API级别11 昨天一切正常,然后突然停止工作 我接受来自健康设备的传入连接的线程是标准的,取自Google的BluetoothChat示例。代码包括在下面。没有例外是抛出和日志猫显示,我的手机正在收听传入的连接刚刚好 我从哪里开始测试这种问题 接受线程:Bluetooth Android手机正在收听蓝牙连接,但蓝牙设备无法连接,bluetooth,spp,Bluetooth,Spp,这里的设备是欧姆龙蓝牙血压监测仪708-BT 健康设备已经与运行安卓4.0.3的HTC Sensation配对 健康设备启动连接,我的Android应用程序应该会接受它。应用程序设置为目标API级别16,最低API级别11 昨天一切正常,然后突然停止工作 我接受来自健康设备的传入连接的线程是标准的,取自Google的BluetoothChat示例。代码包括在下面。没有例外是抛出和日志猫显示,我的手机正在收听传入的连接刚刚好 我从哪里开始测试这种问题 接受线程: private class Acc
private class AcceptThread extends Thread {
// The local server socket
private final BluetoothServerSocket mmServerSocket;
private String mSocketType;
public AcceptThread(boolean secure) {
BluetoothServerSocket tmp = null;
mSocketType = secure ? "Secure":"Insecure";
// Create a new listening server socket
try {
tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_HEALTH_MON, MY_UUID);
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
}
mmServerSocket = tmp;
}
public void run() {
if (D) Log.d(TAG, "Socket Type: " + mSocketType +
"BEGIN mAcceptThread" + this);
setName("AcceptThread" + mSocketType);
BluetoothSocket socket = null;
// Listen to the server socket if we're not connected
while (mState != STATE_CONNECTED) {
try {
// This is a blocking call and will only return on a
// successful connection or an exception
socket = mmServerSocket.accept();
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "accept() failed", e);
break;
}
// If a connection was accepted
if (socket != null) {
synchronized (BluetoothSPPService.this) {
switch (mState) {
case STATE_LISTEN:
case STATE_CONNECTING:
// Situation normal. Start the connected thread.
connected(socket, socket.getRemoteDevice(),
mSocketType);
break;
case STATE_NONE:
case STATE_CONNECTED:
// Either not ready or already connected. Terminate new socket.
try {
socket.close();
} catch (IOException e) {
Log.e(TAG, "Could not close unwanted socket", e);
}
break;
}
}
}
}
if (D) Log.i(TAG, "END mAcceptThread, socket Type: " + mSocketType);
}
public void cancel() {
if (D) Log.d(TAG, "Socket Type" + mSocketType + "cancel " + this);
try {
mmServerSocket.close();
} catch (IOException e) {
Log.e(TAG, "Socket Type" + mSocketType + "close() of server failed", e);
}
}
}
日志:
08-02 17:44:41.055: D/BluetoothSPPService(2956): start
08-02 17:44:41.055: D/BluetoothSPPService(2956): setState() 0 -> 1
08-02 17:45:49.491: D/BluetoothSPPService(2956): Socket Type: SecureBEGIN mAcceptThreadThread[Thread-6798,5,main]
08-02 17:46:07.159: D/BluetoothSPPService(2956): Socket Type: InsecureBEGIN mAcceptThreadThread[Thread-6799,5,main]
08-02 17:48:29.938: D/BluetoothSPPService(3388): start
08-02 17:48:29.938: D/BluetoothSPPService(3388): setState() 0 -> 1
08-02 17:48:41.049: D/BluetoothSPPService(3388): Socket Type: SecureBEGIN mAcceptThreadThread[Thread-6837,5,main]
08-02 17:48:42.730: D/BluetoothSPPService(3388): Socket Type: InsecureBEGIN mAcceptThreadThread[Thread-6838,5,main]
Android蓝牙协议栈有点不稳定。尝试重新启动手机和/或打开/关闭蓝牙。Android中的蓝牙图标会闪烁吗?谢谢@Skaard Solo,我已经试过了。你所说的蓝牙图标闪烁是什么意思,我以前从未见过这样的事情?好吧,当你打开一个监听插座时,Android会注册一个频道和一个蓝牙服务名称。然后,当某种SSP设备想要连接到你的线程时,Android会检测到这个频道和这个BTservice名称。这就是我问这个问题的原因。如果BT图标闪烁,这是因为频道或BTservice名称不匹配;)我的意思是我的HTC Sensation、三星Galaxy S3、HTC Desire或者健康设备有蓝牙图标。我想是你的。您所指的设备是什么?