简体   繁体   English

通过应用程序处理蓝牙spp配对请求

[英]handling bluetooth spp pairing request thru app

My android application is in blueotooth SPP server mode and listening for client devices, my application knows the passcode required for pairing of that devices. 我的android应用程序处于blueotooth SPP服务器模式,正在侦听客户端设备,我的应用程序知道配对该设备所需的密码。

My question is, Is it possible to handle pairing request through application. 我的问题是,是否可以通过应用程序处理配对请求。 Thanks and Regards. 谢谢并恭祝安康。

Yes, it is possible to do pairing through application. 是的,可以通过应用程序进行配对。 I did pairing in my application. 我在应用程序中配对了。 for this you have to made IBluetooth interface object accessible by this way: 为此,您必须通过以下方式使IBluetooth接口对象可访问:

IBluetooth mBluetoothService;
Field fie = Class.forName(bluetoothAdapter.getClass().getName()).getDeclaredField("mService");
fie.setAccessible(true);
mBluetoothService = (IBluetooth) fie.get(bluetoothAdapter);

By using this object you can pair with device using IBluetooth interface functions. 通过使用此对象,您可以使用IBluetooth接口功能与设备配对。 (normal Sequence for Auto Pairing):: (自动配对的正常顺序)::

mBluetoothService.setPin(deviceAddress, PIN);
mBluetoothService.setTrust(deviceAddress);
mBluetoothService.createBond(deviceAddress);
mBluetoothService.setPairingConfirmation(deviceAddress, false);
mBluetoothService.cancelPairingUserInput(deviceAddress);

By using those function you can pair with any BT device programmatically. 通过使用这些功能,您可以以编程方式与任何BT设备配对。

No - because from a security point of view it is important for the user to be aware of pairing. 否-因为从安全角度考虑,让用户知道配对很重要。 The idea is that devices are paired and bonded once, then onwards connections happen automatically initiated by applications without need for re-pairing (or user intervention) 想法是设备配对和绑定一次,然后,应用程序会自动启动连接,而无需重新配对(或用户干预)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM