BluetoothManager BluetoothManager;
BluetoothManager=(bluetoothManager) mContext. GetSystemService (Context. BLUETOOTH_SERVICE);
BluetoothAdapter=bluetoothManager. GetAdapter ();
{if (bluetoothAdapter. IsEnabled ())
BluetoothAdapter. StartLeScan (mLeScanCallback);
}
Correction:
Private final BluetoothAdapter. LeScanCallback mLeScanCallback=new LeScanCallBackClass (this);
Private static final class LeScanCallBackClass implements BluetoothAdapter. LeScanCallback {
WeakReferencethat;
LeScanCallBackClass (ZhongJieFragment saFragment) {
That=new WeakReference<> (saFragment);
}
@ Override
Public void onLeScan (BluetoothDevice device, int rssi, byte [] scanRecord) {
If (device!=null & amp; & Device. The getName (). The startsWith (" BLE device ")) {
//LogUtils. D (TAG, "found that equipment");
Final ZhongShengZhongJieFragment out=that. The get ();
Out. The bluetoothAdapter. StopLeScan (out. MLeScanCallback);
Out. BluetoothDevice=device;
The Message the Message=Message. Obtain ();
Message. What=MSG_HANDLER_CONNECTDEVICE;
Out. The handler. SendMessage (message);
}
}
}
Exit the fragments of time
@ Override
Public void onDestroy () {
Super. OnDestroy ();
If (bluetoothAdapter!=null) {
BluetoothAdapter. StopLeScan (mLeScanCallback);
BluetoothAdapter. Disable ();
}
If (bluetoothGatt!=null) {
RefreshDeviceCache ();
}
If (bluetoothGatt!=null) {
BluetoothGatt. Close ();
}
BluetoothAdapter=null;
CoreGattCallback=null;
The Runtime. GetRuntime (). The gc ();
}