从pairDevice()获取响应
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从pairDevice()获取响应相关的知识,希望对你有一定的参考价值。
我配对设备,我想在我的活动中获得此功能的响应
private void pairDevice(BluetoothDevice device) {
try {
Method method = device.getClass().getMethod("createBond", (Class[]) null);
method.invoke(device, (Object[]) null);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(DeviceListActivity.this, "Nie udalo się sparować urządzenia", Toast.LENGTH_LONG).show();
}
}
答案
您需要注册BroadcastReceiver。
BroadcastReceiver mBondStateBroadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if(intent.getAction() == BluetoothDevice.ACTION_BOND_STATE_CHANGED) {
// do your stuff
}
}
};
final IntentFilter bondFilter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
registerReceiver(mBondStateBroadcastReceiver, bondFilter);
以上是关于从pairDevice()获取响应的主要内容,如果未能解决你的问题,请参考以下文章
Azure 机器人微软Azure Bot 编辑器系列 : 机器人/用户提问回答模式,机器人从API获取响应并组织答案 (The Bot Framework Composer tutorial(代码片段