android - Android BluetoothGatt 类中的 clientIf 字段

标签 android bluetooth-lowenergy

Android BluetoothGatt.classmClientIf 私有(private)字段。大多数与 BLE 事件相关的日志消息都包含此值。例如:

onClientRegistered() - status=0 clientIf=17

mClientIf 字段代表什么?此字段的整数值说明了什么?

最佳答案

mClientf是蓝牙扫描器的scannerId

如果您深入了解 BluetoothGatt 和 BluetoothLeScanner 的源代码,您可以找到以下内容:

mBluetoothGatt.unregisterClient(scannerId);方法实现在

GattService.java unregisterClient(int clientIf)


BluetoothLeScanner.java

...
/**
 * Application interface registered - app is ready to go
 */
@Override
public void onScannerRegistered(int status, int scannerId) {
    Log.d(TAG, "onScannerRegistered() - status=" + status +
            " scannerId=" + scannerId + " mScannerId=" + mScannerId);
    synchronized (this) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            try {
                if (mScannerId == -1) {
                    // Registration succeeds after timeout, unregister client.
                    mBluetoothGatt.unregisterClient(scannerId);
                } else {
                    mScannerId = scannerId;
                    mBluetoothGatt.startScan(mScannerId, mSettings, mFilters,
                            mResultStorages,
                            ActivityThread.currentOpPackageName());
                }
            } catch (RemoteException e) {
                Log.e(TAG, "fail to start le scan: " + e);
                mScannerId = -1;
            }
        } else {
            // registration failed
            mScannerId = -1;
        }
        notifyAll();
    }
}
...

GattService.java

...
/**
 * Unregister the current application and callbacks.
 */
private IBluetoothGatt mService;
.
.   
public void unregisterClient(int clientIf) {
    GattService service = getService();
    if (service == null) return;
    service.unregisterClient(clientIf);
}
...

关于android - Android BluetoothGatt 类中的 clientIf 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158315/

相关文章:

android - 在屏幕上均匀分布 TextView,并左右对齐

Android:收到电话时自动录制视频并将生成的电影文件发送到电子邮件地址

android - 低功耗蓝牙外设模式

ios - PIN 更改后连接到外围设备

android - Fragment 和 Service 正在使用相同的资源

android - 使用Koin库时无法导入ViewModel

ios - 检索外设与标识符 : What devices will be retrieved by this function?

ios - 使用 updateValue :forCharacteristic:onSubscribedCentrals on OS X 时蓝牙崩溃

iphone - 尝试开发一个IOS PhoneGap插件,用于低功耗蓝牙在两部iPhone之间发送数据

安卓图库一掷千金 : how to calculate the necessary velocity for a fling