Android连接和断开与健康设备的连接

时间:2016-05-30 16:49:56

标签: android bluetooth android-bluetooth

我正在创建一个应用程序,使用谷歌的sample project通过Android蓝牙从健康设备(TaiDoc)读取脉搏测量值。

此问题与此问题Unable to connect to bluetooth Health Device Fora using Android BluetoothProfile 2

相同

我尝试了同样的事情并没有试图找出答案。

以下代码检查连接状态

private final BluetoothHealthCallback mHealthCallback = new BluetoothHealthCallback() {
// Callback to handle application registration and unregistration events.     The service
// passes the status back to the UI client.
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
    int status) {
if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_FAILURE) {
    mHealthAppConfig = null;
} else if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_SUCCESS) {
    mHealthAppConfig = config;
} else if (status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_FAILURE ||
        status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS) {
}
}

// Callback to handle channel connection state changes.
// Note that the logic of the state machine may need to be modified based on the HDP device.
// When the HDP device is connected, the received file descriptor is passed to the
// ReadThread to read the content.
public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
    BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd,
    int channelId) {
if (Log.isLoggable(TAG, Log.DEBUG))
    Log.d(TAG, String.format("prevState\t%d ----------> newState\t%d",
            prevState, newState));
if (prevState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED &&
        newState == BluetoothHealth.STATE_CHANNEL_CONNECTED) {
    if (config.equals(mHealthAppConfig)) {
        mChannelId = channelId;

        (new ReadThread(fd)).start();
    } else {

    }
} else if (prevState == BluetoothHealth.STATE_CHANNEL_CONNECTING &&
        newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) {

} else if (newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) {
    if (config.equals(mHealthAppConfig)) {

    } else {

    }
}
}
};

问题

我在onHealthChannelStateChange下的BluetoothHealthCallback中获得2次回调。

  1. 当prevState为= 0且newState = 1时(从断开连接到连接)。
  2. 当prevState = 1且newState = 0时(从连接到断开连接)。
  3. 表示设备未连接或未读取设备

0 个答案:

没有答案