我正在运行使用Android BLE API 24/7扫描BLE设备的后台服务。我的服务使用START_STICKY运行。当我找到一个特定的设备时,我会做我的工作。
我的问题是:当我的设备进入深度睡眠状态时,我是否仍然可以获得ScanCallback,或者我是否需要获取PARTIAL_WAKE_LOCK以防止CPU进入深度睡眠以获取ScanCallback?
感谢。
public class MYService extends IntentService {
public void onCreate() {
super.onCreate();
Log.e("TAG","onCreate");
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
BluetoothLeScanner lEScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
List<ScanFilter> filters = new ArrayList<>();
ScanFilter.Builder sfBuilder = new ScanFilter.Builder();
sfBuilder.setDeviceName(DEVICE_NAME);
sfBuilder.setServiceUuid(ParcelUuid.fromString(ServiceUUID_D1));
filters.add(sfBuilder.build());
lEScanner.startScan(filters,settings,mScanCallback);
}
答案 0 :(得分:0)
您应该在拥有BLE扫描程序的过程中使用Foreground Service,以避免您的应用在后台被杀死。