在Android上使用健康设备配置文件时出现异常
我正在尝试使用健康设备配置文件和样本,通过蓝牙从Onyx2(Fingertip Oximeter)获取数据,可以在上找到。但是我得到了以下错误在Android上使用健康设备配置文件时出现异常,android,sockets,bluetooth,Android,Sockets,Bluetooth,我正在尝试使用健康设备配置文件和样本,通过蓝牙从Onyx2(Fingertip Oximeter)获取数据,可以在上找到。但是我得到了以下错误 E/BluetoothEventLoop.cpp(432):onHealthDeviceConnectionResult:D-Bus错误:org.bluez.error.HealthError(获取远程SDP记录时出错)。 这个问题的原因是什么? 顺便说一句,大约50次中有1次,我得到了数据 // Callbacks to handle connecti
E/BluetoothEventLoop.cpp(432):onHealthDeviceConnectionResult:D-Bus错误:org.bluez.error.HealthError(获取远程SDP记录时出错)
。
这个问题的原因是什么?
顺便说一句,大约50次中有1次,我得到了数据
// 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();
//用于处理连接设置和断开清理的回调。
私有最终BluetoothProfile.ServiceListener mBluetoothServiceListener=
新建BluetoothProfile.ServiceListener(){
服务连接上的公共void(int配置文件、Bluetooth配置文件代理){
if(profile==BluetoothProfile.HEALTH){
mBluetoothHealth=(BluetoothHealth)代理;
if(Log.isLoggable(标记,Log.DEBUG))
Log.d(标记“OnServiceConnectiontoProfile:”+profile);
}
}
服务断开连接时的公共无效(int配置文件){
if(profile==BluetoothProfile.HEALTH){
mBluetoothHealth=null;
}
}
};
私有最终BluetoothHealthCallback mHealthCallback=新BluetoothHealthCallback(){
//回调以处理应用程序注册和注销事件。服务
//将状态传递回UI客户端。
公共无效onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration配置,
int状态){
如果(状态==BluetoothHealth.APP\u配置\u注册\u失败){
mHealthAppConfig=null;
发送消息(状态\运行状况\应用程序\注册,结果\失败);
}else if(状态==BluetoothHealth.APP\u配置\u注册\u成功){
mHealthAppConfig=config;
sendMessage(状态\运行状况\应用程序\注册,结果\确定);
}否则如果(状态==BluetoothHealth.APP\u配置\u注销\u失败||
状态==BluetoothHealth.APP\u配置\u注销\u成功){
sendMessage(状态\运行状况\应用程序\注销,
状态==BluetoothHealth.APP\u配置\u注销\u成功?
结果(正常:结果(失败);
}
}
//回调以处理通道连接状态更改。
//注意,可能需要基于HDP设备修改状态机的逻辑。
//连接HDP设备时,将接收到的文件描述符传递给
//ReadThread以读取内容。
公共无效onHealthChannelStateChange(BluetoothHealthAppConfiguration配置,
Bluetooth设备、int prevState、int newState、ParcelFileDescriptor fd、,
int channelId){
if(Log.isLoggable(标记,Log.DEBUG))
Log.d(TAG,String.format(“prevState\t%d------>newState\t%d”,
前州、新闻州);
如果(prevState==BluetoothHealth.STATE\u通道\u正在连接&&
newState==BluetoothHealth.STATE_通道_已连接){
if(config.equals(mHealthAppConfig)){
mcchannelid=channelId;
sendMessage(状态\创建\通道,结果\确定);
(新的ReadThread(fd)).start();
}否则{
sendMessage(状态\创建\通道,结果\失败);
}
}else if(prevState==BluetoothHealth.STATE\u通道\u正在连接&&
newState==BluetoothHealth.STATE(通道已断开){
sendMessage(状态\创建\通道,结果\失败);
}else if(newState==BluetoothHealth.STATE\u CHANNEL\u DISCONNECTED){
if(config.equals(mHealthAppConfig)){
发送消息(状态\销毁\通道,结果\正常);
}否则{
发送消息(状态\破坏\通道,结果\失败);
}
}
}
};
//通过{@link启动应用程序注册
//BluetoothHDPService}。
按钮注册表AppButton=(按钮)findViewById(R.id.Button\u register\u app);
registerAppButton.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
sendMessage(BluetoothHDPService.MSG_REG_HEALTH_应用程序,
健康状况(个人资料)(来源)(数据)(类型);;
}
});
//通过{@link启动应用程序注销
//BluetoothHDPService}。
Button unregisterAppButton=(按钮)findViewById(R.id.Button\u unregister\u应用程序);
unregisterAppButton.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
sendMessage(BluetoothHDPService.MSG_unr_HEALTH_APP,0);
}
});
//通过{@link BluetoothHDPService}启动通道创建。一些
//设备将
//启动通道连接,在这种情况下,不需要
//在公共场所这样做
//应用程序。按下时,要求用户从以下选项中进行选择:
//键合器件
//连接到。
按钮连接按钮=(按钮)findViewById(R.id.Button\u connect\u channel);
connectButton.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
mAllBondedDevices=(蓝牙设备[])mBluetoothAdapter
.getBondedDevices().toArray(新蓝牙设备[0]);
如果(mAllBondedDevices.length>0){
int deviceCount=mallbondevices.length;
if(mDeviceIndex<设备计数)
mDevice=mAllBondedDevices[mDeviceIndex];
否则{
mDeviceIndex=0;
mDevice=mAllBondedDevices[0];
}
字符串[]设备名称=新字符串[deviceCount];
int i=0;
用于(蓝牙设备:mAllBondedDevices){
deviceNames[i++]=device.getName();
}
SelectDeviceDialogFragment deviceDialog=SelectDeviceDialogFragment
.newInstance(deviceNames、mDeviceIndex);
德维奇