public class BluetoothUtil { public static final String BLUFI_PREFIX = "MH-"; public static BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); public static boolean hasBlueTooth() { return bluetoothAdapter != null; } public static boolean isEnabled() { return bluetoothAdapter != null && bluetoothAdapter.isEnabled(); } public static void startScanBluetooth(ScanCallback scanCallback) { if (isEnabled()) { BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner(); if (scanner == null) { LogUtil.e("蓝牙不可用"); return; } LogUtil.e("开始扫描"); scanner.startScan(null, new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).build(), scanCallback); } } public static void stopScanBluetooth(ScanCallback scanCallback) { if (isEnabled()) { BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner(); if (scanner != null) { scanner.stopScan(scanCallback); } LogUtil.e("停止扫描"); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)