【发布时间】:2014-03-22 21:33:10
【问题描述】:
我正在使用 api 19 中的 setPin() 自动与蓝牙设备配对。我通过广播接收器执行此操作...检查配对请求,然后自动配对。这样做的原因是为了防止用户在我的应用中更改密码后重新输入密码。
有没有办法抑制蓝牙配对请求的通知/对话框?我的代码正确更改了手机上的 PIN 并连接到设备,因此该部分没有问题。我只想摆脱对话框/弹出窗口,以免用户感到困惑。我不介意它是否弹出一秒钟,只要它自动关闭即可。
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// Get the BluetoothDevice object from the Intent
if (btDevice.ACTION_PAIRING_REQUEST.equals(action)) {
Log.i(TAG, "XXXXXXXXXXXXXX PAIRING REQUEST RECEIVED XXXXXXXXXXXXXXXX");
int bondState = btDevice.getBondState();
if (bondState == BluetoothDevice.BOND_NONE || bondState == BluetoothDevice.BOND_BONDING) {
String pinString = settings.getString("com.hiqautomation.iopener.pin", null);
byte[] pinBytes = pinString.getBytes();
btDevice.setPin(pinBytes);
}
}
}
};
【问题讨论】: