Android的蓝牙setpin功能 [英] Android bluetooth setpin function

查看:2174
本文介绍了Android的蓝牙setpin功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid设备正在尝试通过蓝牙连接到传感器上。

My Android device is trying to connect to a sensor via Bluetooth.

作为一个正常的蓝牙设备,我需要以务实的态度设立了销code(通常为0000或1234)

As a normal Bluetooth device, I will need to pragmatically set up the pin code (usually 0000 or 1234)

在传感器侧,因为它是无声的,不会弹出请求对话框。

for the sensor side since it is silent and would not pop up the request dialogue.

我没有找到在Android开发网站的任何相关线索。

I did not find any related clue on the Android dev site.

有没有人能告诉我,如果有任何的方法可以实现这一目标?

Does anyone can tell me if there is any approach available to achieve this?

推荐答案

要设置密码,可以通过反射的隐藏方法 setPin(字节[])从调用 BluetoothDevice类类。

To set the PIN, you can call by reflection the hidden method setPin(byte[]) from BluetoothDevice class.

例如:

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());
}

其中,设备 BluetoothDevice类 A 字节[] 数组,它包含了蓝牙器件引脚。

Where device is your BluetoothDevice and pin a byte[] array which contains the bluetooth device pin.

不过,我认为,你会preFER使用方法 setPasskey(INT)。因为你想设置,如0000或1234一个密钥这将是您更轻松。

But I think, you'll prefer to use the method setPasskey(int). It would be easier for you because you want to set a passkey like "0000" or "1234".

  • Source: www.androidjavadoc.com/BluetoothDevice#setPin(byte[])
  • Source: www.androidjavadoc.com/BluetoothDevice#setPasskey(int)

这篇关于Android的蓝牙setpin功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆