/**
* 搜索Ble设备
* @param enable
*/
public void scanBle(boolean enable) {
// TODO Auto-generated method stub
if (!isBleAvailable) {
Intent intent = new Intent();
intent.setAction(ActionBleNotify.ACTION_BLE_NOT_AVAILABLE);
mContext.sendBroadcast(intent);
return;
}
if (isBleEnabled()) {
if (enable) {
// Stops scanning after a pre-defined scan period.
if(mScanning){
scanBle(false);
}
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if(mScanning){
if (mOnBleScanListener!=null) {
mOnBleScanListener.stop();
}
mBluetoothAdapter.stopLeScan(mLeScanCallback);
mScanning = false;
}
}
}, SCAN_PERIOD);
if (mOnBleScanListener!=null) {
mOnBleScanListener.start();
}
mScanning = true;
mBluetoothAdapter.startLeScan(mLeScanCallback);
// mBluetoothAdapter.startLeScan(BTTempBLEService.uuids, mLeScanCallback);
} else {
if (mOnBleScanListener!=null) {
mOnBleScanListener.stop();
}
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
} else {
Intent intent = new Intent();
intent.setAction(ActionBleNotify.ACTION_BLE_NOT_ENABLED);
mContext.sendBroadcast(intent);
}
}
private BluetoothAdapter.LeScanCallback mLeScanCallback;
很多人说用stopScan()、startScan()方法替代,如果是,请告诉如何替代,谢谢!