Browse Source

调整蓝牙设备链接逻辑

master
白凤吉 4 months ago
parent
commit
e17d488ce6
  1. 25
      app/build.gradle
  2. 4
      app/src/main/assets/web/asset-manifest.json
  3. 2
      app/src/main/assets/web/index.html
  4. 4
      app/src/main/assets/web/static/js/main.7ec89011.js
  5. 0
      app/src/main/assets/web/static/js/main.7ec89011.js.LICENSE.txt
  6. 3
      app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java
  7. 30
      app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java

25
app/build.gradle

@ -16,13 +16,29 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
//
versionCode 2
//
versionName "1.1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
signingConfigs {
release {
// keystore
storeFile file("keystore/release.keystore")
storePassword "iflytop#110011"
keyAlias "iflytop"
keyPassword "iflytop#110011"
}
}
buildTypes { buildTypes {
release { release {
minifyEnabled false
minifyEnabled true//
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release// release 使
} }
} }
compileOptions { compileOptions {
@ -35,6 +51,13 @@ android {
} }
} }
android.applicationVariants.configureEach { variant ->
variant.outputs.configureEach { output ->
def buildType = variant.buildType.name
outputFileName = "廓形仪-${buildType}-v${variant.versionName}.apk"
}
}
tasks.withType(KotlinCompile).configureEach { tasks.withType(KotlinCompile).configureEach {
kotlinOptions { kotlinOptions {
jvmTarget = "21" jvmTarget = "21"

4
app/src/main/assets/web/asset-manifest.json

@ -1,7 +1,7 @@
{ {
"files": { "files": {
"main.css": "./static/css/main.3543332f.css", "main.css": "./static/css/main.3543332f.css",
"main.js": "./static/js/main.d1cfebe4.js",
"main.js": "./static/js/main.7ec89011.js",
"static/js/206.d71bd05f.chunk.js": "./static/js/206.d71bd05f.chunk.js", "static/js/206.d71bd05f.chunk.js": "./static/js/206.d71bd05f.chunk.js",
"static/media/icon_tab3_u.svg": "./static/media/icon_tab3_u.6d18cbd7c4dc6a54f745fdfcc7716050.svg", "static/media/icon_tab3_u.svg": "./static/media/icon_tab3_u.6d18cbd7c4dc6a54f745fdfcc7716050.svg",
"static/media/icon_tab3_s.svg": "./static/media/icon_tab3_s.b0a9cbf5ecee59829c9de63a2e9de169.svg", "static/media/icon_tab3_s.svg": "./static/media/icon_tab3_s.b0a9cbf5ecee59829c9de63a2e9de169.svg",
@ -22,6 +22,6 @@
}, },
"entrypoints": [ "entrypoints": [
"static/css/main.3543332f.css", "static/css/main.3543332f.css",
"static/js/main.d1cfebe4.js"
"static/js/main.7ec89011.js"
] ]
} }

2
app/src/main/assets/web/index.html

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><title>廓形仪</title><script defer="defer" src="./static/js/main.d1cfebe4.js"></script><link href="./static/css/main.3543332f.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>function setupWebViewJavascriptBridge(e){if(window.WebViewJavascriptBridge)return e(WebViewJavascriptBridge);if(/android/i.test(navigator.userAgent))document.addEventListener("WebViewJavascriptBridgeReady",(function(){e(WebViewJavascriptBridge)}),!1);else{if(window.WVJBCallbacks)return window.WVJBCallbacks.push(e);window.WVJBCallbacks=[e];var i=document.createElement("iframe");i.style.display="none",i.src="https://__bridge_loaded__",document.documentElement.appendChild(i),setTimeout((function(){document.documentElement.removeChild(i)}),0)}}setupWebViewJavascriptBridge((function(e){window.bridge=e}));var SyncBridgeJS={call:function(e,i){return prompt("sync/syncBridge/"+e,i)}}</script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><title>廓形仪</title><script defer="defer" src="./static/js/main.7ec89011.js"></script><link href="./static/css/main.3543332f.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>function setupWebViewJavascriptBridge(e){if(window.WebViewJavascriptBridge)return e(WebViewJavascriptBridge);if(/android/i.test(navigator.userAgent))document.addEventListener("WebViewJavascriptBridgeReady",(function(){e(WebViewJavascriptBridge)}),!1);else{if(window.WVJBCallbacks)return window.WVJBCallbacks.push(e);window.WVJBCallbacks=[e];var i=document.createElement("iframe");i.style.display="none",i.src="https://__bridge_loaded__",document.documentElement.appendChild(i),setTimeout((function(){document.documentElement.removeChild(i)}),0)}}setupWebViewJavascriptBridge((function(e){window.bridge=e}));var SyncBridgeJS={call:function(e,i){return prompt("sync/syncBridge/"+e,i)}}</script></body></html>

4
app/src/main/assets/web/static/js/main.7ec89011.js
File diff suppressed because it is too large
View File

0
app/src/main/assets/web/static/js/main.d1cfebe4.js.LICENSE.txt → app/src/main/assets/web/static/js/main.7ec89011.js.LICENSE.txt

3
app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java

@ -3,6 +3,7 @@ package com.iflytop.profilometer.api.ws;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGatt;
import android.util.Log;
import com.iflytop.profilometer.core.bluetooth.BleManager; import com.iflytop.profilometer.core.bluetooth.BleManager;
import com.iflytop.profilometer.core.websocket.WebSocketManager; import com.iflytop.profilometer.core.websocket.WebSocketManager;
@ -71,7 +72,7 @@ public class BleWebsocketManager {
bleList.sort(Comparator.comparing(map -> (String) map.get("mac"))); bleList.sort(Comparator.comparing(map -> (String) map.get("mac")));
listMap.put("data", bleList); listMap.put("data", bleList);
WebSocketManager.send(JSONUtil.toJsonStr(listMap)); WebSocketManager.send(JSONUtil.toJsonStr(listMap));
}, 0, 2000, TimeUnit.MILLISECONDS);
}, 0, 100, TimeUnit.MILLISECONDS);
} }
/** /**

30
app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java

@ -17,6 +17,7 @@ import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.BluetoothLeScanner; import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback; import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -329,7 +330,7 @@ public class BleManager {
public void onScanResult(int callbackType, ScanResult result) { public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice device = result.getDevice(); BluetoothDevice device = result.getDevice();
// 仅处理设备名非空的设备 // 仅处理设备名非空的设备
if (device != null && device.getName() != null) {
if (device != null && device.getName() != null && device.getName().startsWith("SPM")) {
if (result.getScanRecord() != null) { if (result.getScanRecord() != null) {
deviceLastSeenMap.put(device, System.currentTimeMillis()); deviceLastSeenMap.put(device, System.currentTimeMillis());
} }
@ -341,16 +342,21 @@ public class BleManager {
if (!isConnected()) { if (!isConnected()) {
connectToDevice(address); connectToDevice(address);
} }
processedDevices.add(address);
// processedDevices.add(address);
return; return;
} }
// 避免重复处理
if (processedDevices.contains(address)) {
return;
if (!scannedDevices.contains(device)) {
scannedDevices.add(device);
Log.d(TAG, "设备 " + device.getName() + "," + device.getAddress() + " ,已添加至列表");
} }
processedDevices.add(address);
// 对扫描到的设备进行连接查询服务
device.connectGatt(context, false, new ServiceDiscoveryGattCallback(device));
// // 避免重复处理
// if (processedDevices.contains(address)) {
// return;
// }
// processedDevices.add(address);
// // 对扫描到的设备进行连接查询服务
// device.connectGatt(context, false, new ServiceDiscoveryGattCallback(device));
} }
} }
@ -388,8 +394,12 @@ public class BleManager {
} }
}; };
// 开始扫描此处未使用 ScanFilter若设备广播中包含目标服务 UUID 也可添加过滤器
bluetoothLeScanner.startScan(scanCallback);
ScanSettings settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) // 使用最低延迟模式
.setReportDelay(0) // 立即报告扫描结果
.build();
bluetoothLeScanner.startScan(null, settings, scanCallback);
cleanupHandler.postDelayed(cleanupRunnable, CLEANUP_INTERVAL); cleanupHandler.postDelayed(cleanupRunnable, CLEANUP_INTERVAL);
} }

Loading…
Cancel
Save