Auto-accept bluetooth pairing possible?

前端 未结 3 773
长情又很酷
长情又很酷 2020-12-06 03:39

In the Android 2.3.3 BluetoothChat example with with createInsecureRfcommSocketToServiceRecord() API, users are still prompted to accept the pairing request, even though no

3条回答
  •  借酒劲吻你
    2020-12-06 04:36

    i came across the same problem, i hope the following code will help: firsly we need:

    secondly we need the BluetoothDevice class, and:

    public class PairingRequest extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent){
    if (intent.getAction().equals("ACTION_PAIRING_REQUEST")) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
            device.setPin(pinBytes);
        }
     }
    }
    

提交回复
热议问题