Java 类android.bluetooth.BluetoothGattServerCallback 实例源码

项目:unity-bluetooth    文件:BLEServicePeripheral.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void start(String uuidString) {
    mServiceUUID = UUID.fromString(uuidString);
    if (mBtAdvertiser == null) {
        return;
    }

    BluetoothGattService btGattService = new BluetoothGattService(mServiceUUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
    btGattService.addCharacteristic(mBtGattCharacteristic);
    BluetoothGattServerCallback btGattServerCallback = createGattServerCallback(mServiceUUID, UUID.fromString(CHARACTERISTIC_UUID));
    mBtGattServer = mBtManager.openGattServer(mActivity.getApplicationContext(), btGattServerCallback);
    mBtGattServer.addService(btGattService);

    mDataBuilder = new AdvertiseData.Builder();
    mDataBuilder.setIncludeTxPowerLevel(false);
    mDataBuilder.addServiceUuid(new ParcelUuid(mServiceUUID));

    mSettingsBuilder=new AdvertiseSettings.Builder();
    mSettingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    mSettingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);

    mBleAdvertiser = mBtAdapter.getBluetoothLeAdvertiser();
    mBleAdvertiser.startAdvertising(mSettingsBuilder.build(), mDataBuilder.build(), mAdvertiseCallback);
}