从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(代码片段

从Snipplr获取一个代码片段

如何从Android片段中的相机获取图像

VSCode自定义代码片段—— 数组的响应式方法

VSCode自定义代码片段10—— 数组的响应式方法

如何从 Firebase 获取数据到 Recyclerview 中的片段?