我的Android设备正试图通过蓝牙连接到传感器.
作为普通的蓝牙设备,我需要实际设置密码(通常为0000或1234)
对于传感器方面,因为它是静音的,不会弹出请求对话框.
我没有在Android开发网站上找到任何相关的线索.
有没有人可以告诉我是否有任何方法可以实现这一目标?
要设置密码,可以通过反射调用隐藏方法setPin(byte[])从BluetoothDevice类.
例:
try {
Log.d("setPin()", "Try to set the PIN");
Method m = device.getClass().getMethod("setPin", byte[].class);
m.invoke(device, pin);
Log.d("setPin()", "Success to add the PIN");
} catch (Exception e) {
Log.e("setPin()", e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
device您BluetoothDevice和包含蓝牙设备引脚pin的byte[]阵列在哪里?
但我认为,你更愿意使用这种方法setPasskey(int).这对你来说会更容易,因为你想设置一个像"0000"或"1234"这样的密码.
[UPDATE]
以前的源链接已经死亡,类已更新.显然setPasskey不再存在了.请按照下面的文档链接查找所需信息.
资料来源:BluetoothDevice Android文档
| 归档时间: |
|
| 查看次数: |
6328 次 |
| 最近记录: |