android.bluetooth.BluetoothGatt#requestMtu ( )源码实例Demo

下面列出了android.bluetooth.BluetoothGatt#requestMtu ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: physical-web   文件: BluetoothSite.java
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
  if (newState == BluetoothProfile.STATE_CONNECTED && status == gatt.GATT_SUCCESS) {
    Log.i(TAG, "Connected to GATT server");
    mBluetoothGatt = gatt;
    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
      gatt.requestConnectionPriority(CONNECTION_PRIORITY_HIGH);
      gatt.requestMtu(505);
    } else {
      gatt.discoverServices();
    }
  } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
    Log.i(TAG, "Disconnected to GATT server");
    // ensure progress dialog is removed and running is set false
    close();
  } else if (status != gatt.GATT_SUCCESS) {
    Log.i(TAG, "Status is " + status);
    close();
  }
}
 
源代码2 项目: SimpleBluetoothLeTerminal   文件: SerialSocket.java
private void connectCharacteristics2(BluetoothGatt gatt) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Log.d(TAG, "request max MTU");
        if (!gatt.requestMtu(MAX_MTU))
            onSerialConnectError(new IOException("request MTU failed"));
        // continues asynchronously in onMtuChanged
    } else {
        connectCharacteristics3(gatt);
    }
}
 
源代码3 项目: bitgatt   文件: RequestMtuGattTransaction.java
@Override
protected void transaction(GattTransactionCallback callback) {
    super.transaction(callback);
    getConnection().setState(GattState.REQUESTING_MTU);
    boolean success = false;
    if(FitbitGatt.atLeastSDK(LOLLIPOP)) {
        BluetoothGatt localGatt = getConnection().getGatt();
        if(localGatt != null) {
            success = localGatt.requestMtu(this.mtu);
        } else {
            Timber.w("Couldn't request a new MTU because the gatt was null");
        }
        if(success) {
            return;
        }
    } else {
        Timber.v("[%s] This can only be done on Lollipop and higher", getDevice());
    }
    getConnection().setState(GattState.REQUEST_MTU_FAILURE);
    TransactionResult.Builder builder = new TransactionResult.Builder().transactionName(getName());
    builder.gattState(getConnection().getGattState())
            .resultStatus(TransactionResult.TransactionResultStatus.FAILURE);
    mainThreadHandler.post(() -> {
        callCallbackWithTransactionResultAndRelease(callback, builder.build());
        getConnection().setState(GattState.IDLE);
    });
}
 
源代码4 项目: EasyBle   文件: BleGattImpl.java
@SuppressWarnings("NewApi")
@Override
public void setMtu(final BleDevice device, int mtu, final BleMtuCallback callback) {
    checkNotNull(callback, BleMtuCallback.class);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                callback.onFailure(BleCallback.FAIL_OTHER,
                        "The minimum android api version which setMtu supports is 21", device);
            }
        });
        return;
    }
    if (!checkConnection(device, callback)) {
        return;
    }
    mMtuCallbackMap.put(device.address, callback);
    BluetoothGatt gatt = mGattMap.get(device.address);
    if (mtu < 23) {
        mtu = 23;
    } else if (mtu > 512) {
        mtu = 512;
    }
    if (gatt == null || !gatt.requestMtu(mtu)) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                callback.onFailure(BleCallback.FAIL_OTHER, "fail to read rssi because of unknown reason", device);
            }
        });
    }
}
 
源代码5 项目: Android-BLE-Library   文件: BleManagerHandler.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private boolean internalRequestMtu(@IntRange(from = 23, to = 517) final int mtu) {
	final BluetoothGatt gatt = bluetoothGatt;
	if (gatt == null || !connected)
		return false;

	log(Log.VERBOSE, "Requesting new MTU...");
	log(Log.DEBUG, "gatt.requestMtu(" + mtu + ")");
	return gatt.requestMtu(mtu);
}
 
源代码6 项目: Android-nRF-Toolbox   文件: BleManager.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private boolean internalRequestMtu(final int mtu) {
	final BluetoothGatt gatt = bluetoothGatt;
	if (gatt == null)
		return false;

	return gatt.requestMtu(mtu);
}
 
源代码7 项目: RxAndroidBle   文件: MtuRequestOperation.java
@Override
protected boolean startOperation(BluetoothGatt bluetoothGatt) {
    return bluetoothGatt.requestMtu(mtu);
}
 
源代码8 项目: AsteroidOSSync   文件: L_Util.java
public static boolean requestMtu(BluetoothGatt gatt, int mtu) {
    return gatt.requestMtu(mtu);
}
 
源代码9 项目: SweetBlue   文件: L_Util.java
public static boolean requestMtu(BluetoothGatt gatt, int mtu) {
    return gatt.requestMtu(mtu);
}