我正在开发用于蓝牙通信的Android应用程序。
我的问题是为什么这个函数
public BluetoothGatt connectGatt(Context context, boolean autoConnect,BluetoothGattCallback callback, int transport)
此函数需要 Context
作为参数,我深入挖掘了这个函数并发现它在任何地方都没有使用它,你可以在这里看到:
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport,
boolean opportunistic, int phy, Handler handler) {
if (callback == null)
throw new NullPointerException("callback is null");
// TODO(Bluetooth) check whether platform support BLE
// Do the check here or in GattServer?
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
IBluetoothManager managerService = adapter.getBluetoothManager();
try {
IBluetoothGatt iGatt = managerService.getBluetoothGatt();
if (iGatt == null) {
// BLE is not supported
return null;
}
BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, opportunistic, phy);
gatt.connect(autoConnect, callback, handler);
return gatt;
} catch (RemoteException e) {Log.e(TAG, "", e);}
return null;
}
奇怪的是,这个属性没有被标记为废弃。
我尝试传递 null 而不是上下文,似乎在有上下文或无上下文的情况下都可以正常工作。
有人知道为什么吗?