|
@ -14,6 +14,8 @@ import java.util.concurrent.ScheduledExecutorService; |
|
|
import java.util.concurrent.ScheduledFuture; |
|
|
import java.util.concurrent.ScheduledFuture; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
|
|
|
|
public class BleWebsocketManager { |
|
|
public class BleWebsocketManager { |
|
|
private static BleWebsocketManager instance; |
|
|
private static BleWebsocketManager instance; |
|
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); |
|
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); |
|
@ -40,10 +42,10 @@ public class BleWebsocketManager { |
|
|
scheduledTask = scheduler.scheduleWithFixedDelay(() -> { |
|
|
scheduledTask = scheduler.scheduleWithFixedDelay(() -> { |
|
|
List<BluetoothDevice> scannedDevices = BleManager.getInstance(context).getScannedDevices(); |
|
|
List<BluetoothDevice> scannedDevices = BleManager.getInstance(context).getScannedDevices(); |
|
|
List<String> bleList = new ArrayList<>(); |
|
|
List<String> bleList = new ArrayList<>(); |
|
|
for(BluetoothDevice bluetoothDevice : scannedDevices){ |
|
|
|
|
|
|
|
|
for (BluetoothDevice bluetoothDevice : scannedDevices) { |
|
|
bleList.add(bluetoothDevice.getName() + "_" + bluetoothDevice.getAddress()); |
|
|
bleList.add(bluetoothDevice.getName() + "_" + bluetoothDevice.getAddress()); |
|
|
} |
|
|
} |
|
|
WebSocketManager.send(GsonUtil.toJson(bleList)); |
|
|
|
|
|
|
|
|
WebSocketManager.send(JSONUtil.toJsonStr(bleList)); |
|
|
}, 2, 2, TimeUnit.SECONDS); |
|
|
}, 2, 2, TimeUnit.SECONDS); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|