| | |
| | | filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED); |
| | | filter.addAction("android.bluetooth.device.action.PAIRING_REQUEST"); |
| | | |
| | | filter.setPriority(1000); |
| | | // filter.setPriority(1000); |
| | | |
| | | context.registerReceiver(this, filter); |
| | | } |
| | |
| | | OpenBluetooth(); |
| | | } |
| | | } else if (action.equals("android.bluetooth.device.action.PAIRING_REQUEST")) { |
| | | Log.d(TAG, "匹配请求"); |
| | | // Get the BluetoothDevice object from the Intent |
| | | BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); |
| | | |
| | | String name = device.getName(); |
| | | |
| | | Log.d(TAG, "匹配请求 " + name); |
| | | |
| | | if (pin == null && name != null && name.contains("AKS3A_") && name.length() >= 8) { |
| | | char [] sn = new char[8]; |
| | |
| | | pin = DEFAULT_BT_PASSWORD; |
| | | } |
| | | |
| | | Log.d(TAG, "匹配吗 " + pin); |
| | | Log.d(TAG, "蓝牙Pin " + pin); |
| | | /*if (device.getName().equals(BLUETOOTH_OBD_NAME) || device.getName().equals(BLUETOOTH_TARGET2_NAME)) */{ |
| | | try { |
| | | ClsUtils.setPairingConfirmation(device.getClass(), device, true); |
| | | // 第三方的系统需要注释掉,否则会抛异常 |
| | | // ClsUtils.setPairingConfirmation(device.getClass(), device, true); |
| | | Log.d(TAG, "isOrderedBroadcast:"+isOrderedBroadcast()+",isInitialStickyBroadcast:"+isInitialStickyBroadcast()); |
| | | if (isOrderedBroadcast()) { |
| | | abortBroadcast(); |
| | |
| | | |
| | | ClsUtils.setPin(device.getClass(), device, pin); |
| | | } catch (Exception e) { |
| | | Log.e(TAG, e.getMessage()); |
| | | |
| | | } |
| | | } |
| | | } else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) { |