首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android上使用健康设备配置文件时出现异常

问在Android上使用健康设备配置文件时出现异常
EN

Stack Overflow用户
提问于 2013-03-08 19:16:54
回答 1查看 1.4K关注 0票数 0

我正在尝试使用健康设备配置文件和样本通过蓝牙从Onyx2(指尖血氧仪)获取数据,这些数据可以在Android Developers site上找到。但是我得到了以下错误

E/BluetoothEventLoop.cpp(432): onHealthDeviceConnectionResult: D-Bus error: org.bluez.Error.HealthError (Error getting remote SDP records)。导致此问题的原因是什么?顺便说一句,大约50次中有1次,我得到了数据。

代码语言:javascript
复制
// Callbacks to handle connection set up and disconnection clean up.
private final BluetoothProfile.ServiceListener mBluetoothServiceListener =
        new BluetoothProfile.ServiceListener() {
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.HEALTH) {
            mBluetoothHealth = (BluetoothHealth) proxy;
            if (Log.isLoggable(TAG, Log.DEBUG))
                Log.d(TAG, "onServiceConnected to profile: " + profile);
        }
    }

    public void onServiceDisconnected(int profile) {
        if (profile == BluetoothProfile.HEALTH) {
            mBluetoothHealth = null;
        }
    }
};

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;
            sendMessage(STATUS_HEALTH_APP_REG, RESULT_FAIL);
        } else if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_SUCCESS) {
            mHealthAppConfig = config;
            sendMessage(STATUS_HEALTH_APP_REG, RESULT_OK);
        } else if (status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_FAILURE ||
                status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS) {
            sendMessage(STATUS_HEALTH_APP_UNREG,
                    status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS ?
                    RESULT_OK : RESULT_FAIL);
        }
    }

    // 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_CONNECTING &&
                newState == BluetoothHealth.STATE_CHANNEL_CONNECTED) {
            if (config.equals(mHealthAppConfig)) {
                mChannelId = channelId;
                sendMessage(STATUS_CREATE_CHANNEL, RESULT_OK);
                (new ReadThread(fd)).start();
            } else {
                sendMessage(STATUS_CREATE_CHANNEL, RESULT_FAIL);
            }
        } else if (prevState == BluetoothHealth.STATE_CHANNEL_CONNECTING &&
                   newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) {
            sendMessage(STATUS_CREATE_CHANNEL, RESULT_FAIL);
        } else if (newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) {
            if (config.equals(mHealthAppConfig)) {
                sendMessage(STATUS_DESTROY_CHANNEL, RESULT_OK);
            } else {
                sendMessage(STATUS_DESTROY_CHANNEL, RESULT_FAIL);
            }
        }
    }
};
// Initiates application registration through {@link
    // BluetoothHDPService}.
    Button registerAppButton = (Button) findViewById(R.id.button_register_app);
    registerAppButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sendMessage(BluetoothHDPService.MSG_REG_HEALTH_APP,
                    HEALTH_PROFILE_SOURCE_DATA_TYPE);
        }
    });

    // Initiates application unregistration through {@link
    // BluetoothHDPService}.
    Button unregisterAppButton = (Button) findViewById(R.id.button_unregister_app);
    unregisterAppButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sendMessage(BluetoothHDPService.MSG_UNREG_HEALTH_APP, 0);
        }
    });

    // Initiates channel creation through {@link BluetoothHDPService}. Some
    // devices will
    // initiate the channel connection, in which case, it is not necessary
    // to do this in the
    // application. When pressed, the user is asked to select from one of
    // the bonded devices
    // to connect to.
    Button connectButton = (Button) findViewById(R.id.button_connect_channel);
    connectButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mAllBondedDevices = (BluetoothDevice[]) mBluetoothAdapter
                    .getBondedDevices().toArray(new BluetoothDevice[0]);

            if (mAllBondedDevices.length > 0) {
                int deviceCount = mAllBondedDevices.length;
                if (mDeviceIndex < deviceCount)
                    mDevice = mAllBondedDevices[mDeviceIndex];
                else {
                    mDeviceIndex = 0;
                    mDevice = mAllBondedDevices[0];
                }
                String[] deviceNames = new String[deviceCount];
                int i = 0;
                for (BluetoothDevice device : mAllBondedDevices) {
                    deviceNames[i++] = device.getName();
                }
                SelectDeviceDialogFragment deviceDialog = SelectDeviceDialogFragment
                        .newInstance(deviceNames, mDeviceIndex);
                deviceDialog.show(getFragmentManager(), "deviceDialog");
            }
        }
    });

    // Initiates channel disconnect through {@link BluetoothHDPService}.
    Button disconnectButton = (Button) findViewById(R.id.button_disconnect_channel);
    disconnectButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            disconnectChannel();
        }
    });
    registerReceiver(mReceiver, initIntentFilter());
}

// Sets up communication with {@link BluetoothHDPService}.
private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName name, IBinder service) {
        mHealthServiceBound = true;
        Message msg = Message.obtain(null,
                BluetoothHDPService.MSG_REG_CLIENT);
        msg.replyTo = mMessenger;
        mHealthService = new Messenger(service);
        try {
            mHealthService.send(msg);
        } catch (RemoteException e) {
            Log.w(TAG, "Unable to register client to service.");
            e.printStackTrace();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-20 02:45:33

我记得Android HDP演示应用程序有一些问题,在终止时没有关闭蓝牙连接。您可以执行的一个测试来验证这一点:

  • 关闭您的安卓系统的蓝牙。
  • 将其重新打开。
  • 与健康设备配对(在安卓系统中,您的安卓application.
  • Try可与健康设备连接并传输数据。

如果这些步骤在重复时一直有效,我几乎可以肯定这与应用程序没有像我之前说的那样释放资源有关。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15292726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档