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;
}
GrandroidBle.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:Grandroid2
作者:
评论列表
文章目录