从pairDevice()获取响应

问题描述 投票:-1回答:1

我配对设备,我想在我的活动中获得此功能的响应

 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();
        }
    }
java android
1个回答
1
投票

您需要注册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);
© www.soinside.com 2019 - 2024. All rights reserved.