From 1baa8f7baa336ce7e78d4b8389a351526cb8c673 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期三, 25 十一月 2020 15:10:39 +0800
Subject: [PATCH] 蓝牙密码
---
lib/src/main/java/com/anyun/exam/lib/util/Bluetooth.java | 28 +++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/lib/src/main/java/com/anyun/exam/lib/util/Bluetooth.java b/lib/src/main/java/com/anyun/exam/lib/util/Bluetooth.java
index 91b66b1..eb40b1a 100644
--- a/lib/src/main/java/com/anyun/exam/lib/util/Bluetooth.java
+++ b/lib/src/main/java/com/anyun/exam/lib/util/Bluetooth.java
@@ -15,13 +15,13 @@
public class Bluetooth extends BroadcastReceiver {
private static final String TAG = Bluetooth.class.getCanonicalName();
- public static final String DEFAULT_BT_PASSWORD = "0000";
+ public static final String DEFAULT_BT_PASSWORD = "1111";
private static Bluetooth instance = null;
private Context context;
private BluetoothAdapter mBtAdapter = null;
private Handler mHandler;
- private String pin = DEFAULT_BT_PASSWORD;
+ private String pin = null;
private String mName = null;
public static Bluetooth getInstance(Context context, Handler handler) {
@@ -46,6 +46,9 @@
filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
filter.addAction("android.bluetooth.device.action.PAIRING_REQUEST");
+
+ filter.setPriority(1000);
+
context.registerReceiver(this, filter);
}
@@ -129,6 +132,25 @@
Log.d(TAG, "鍖归厤璇锋眰");
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+ String name = device.getName();
+
+ if (pin == null && name != null && name.contains("AKS3A_") && name.length() >= 8) {
+ char [] sn = new char[8];
+ name.getChars(name.length() - 8, name.length(), sn, 0);
+ int a = ((sn[0] - '0') * 10 + sn[1] - '0') * 100 + (sn[2] - '0') * 10 + sn[3] - '0';
+ int b = ((sn[4] - '0') * 10 + sn[5] - '0') * 100 + (sn[6] - '0') * 10 + sn[7] - '0';
+
+ a = (a * b * 1978) % 10000;
+
+ pin = String.format("%02d", a/100) + String.format("%02d", a%100);
+ }
+
+ if (pin == null) {
+ pin = DEFAULT_BT_PASSWORD;
+ }
+
+ Log.d(TAG, "鍖归厤鍚� " + pin);
/*if (device.getName().equals(BLUETOOTH_OBD_NAME) || device.getName().equals(BLUETOOTH_TARGET2_NAME)) */{
try {
ClsUtils.setPairingConfirmation(device.getClass(), device, true);
@@ -139,7 +161,7 @@
ClsUtils.setPin(device.getClass(), device, pin);
} catch (Exception e) {
- e.printStackTrace();
+ Log.e(TAG, e.getMessage());
}
}
} else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
--
Gitblit v1.8.0