GrandroidBle.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:Grandroid2 作者:
public boolean init(ConnectionListener connectionListener) {
    this.connectionListener = connectionListener;
    BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
    if (bluetoothManager == null) {
        Config.loge("Unable to initialize BluetoothManager.");
        return false;
    }
    bluetoothAdapter = bluetoothManager.getAdapter();
    if (bluetoothAdapter == null) {
        Config.loge("Unable to obtain a BluetoothAdapter.");
        return false;
    }
    Intent gattServiceIntent = new Intent(context, BluetoothLeService.class);
    context.bindService(gattServiceIntent, serviceConnection, Activity.BIND_AUTO_CREATE);
    Config.loge("startScan to Bind service.");
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothLeService.ACTION_GATT_CONNECTED);
    intentFilter.addAction(BluetoothLeService.ACTION_GATT_DISCONNECTED);
    intentFilter.addAction(BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED);
    intentFilter.addAction(BluetoothLeService.ACTION_DATA_AVAILABLE);
    intentFilter.addAction(BluetoothLeService.ACTION_READ_RSSI);
    intentFilter.addAction(BluetoothLeService.ACTION_CHARACTERISTIV_WRITE);
    context.registerReceiver(mGattUpdateReceiver, intentFilter);
    return true;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号