该设备是欧姆龙蓝牙血压计 708-BT。
健康设备已与运行 Android 4.0.3 的 HTC Sensation 配对。
健康设备启动连接,我的 Android 应用程序应该接受它。该应用程序设置为以 API 级别 16 为目标,最低 API 级别为 11。
昨天一切正常,然后突然停止工作。
我接受来自健康设备的传入连接的线程是从 Google 的 BluetoothChat 示例中获取的标准。代码包含在下面。throw 也不例外,log cat 显示我的手机正在监听传入的连接。
我从哪里开始测试这类问题?
接受线程:
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]