本文整理汇总了Java中android.bluetooth.BluetoothGatt.requestMtu方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGatt.requestMtu方法的具体用法?Java BluetoothGatt.requestMtu怎么用?Java BluetoothGatt.requestMtu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothGatt
的用法示例。
在下文中一共展示了BluetoothGatt.requestMtu方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMtuChanged
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
if ( status == BluetoothGatt.GATT_SUCCESS )
{
NLog.d("call onMtuChanged");
gatt.discoverServices();
}
else
{
// 적용가능한 최대 크기의 MTU찾기
NLog.d("call onMtuChanged status : " + status + ", mtu : " + mtu);
if ( mtuIndex >= mtuLIst.length )
{
NLog.d("error request mtu failed");
}
BTLEAdt.this.mtu = BTLEAdt.this.mtuLIst[++mtuIndex];
gatt.requestMtu(BTLEAdt.this.mtu);
}
}
示例2: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
NLog.d("onConnectionStatusChange status " + status + ", newStatue " + newState);
super.onConnectionStateChange(gatt, status, newState);
watchDog.cancel();
if ( watchDogAlreadyCalled )
{
return;
}
switch (newState)
{
case BluetoothProfile.STATE_CONNECTED:
mBluetoothGatt = gatt;
onBinded();
NLog.d("Connected");
mtuIndex = 0;
mtu = mtuLIst[mtuIndex];
boolean ret = gatt.requestMtu(mtu);
NLog.d("mtu test result : " + ret);
break;
case BluetoothProfile.STATE_DISCONNECTED:
NLog.d("Disconnected");
if ( mConnectionThread == null )
{
NLog.d("Connect failed");
responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE) );
onDisconnected();
}
else
{
mConnectionThread.stopRunning();
}
close();
break;
}
}
示例3: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
//gatt.discoverServices();
gatt.requestMtu(69);
if (mProvServerDev != null) {
if (mProvServerDev.getGattClient() != null) {
if (mProvServerDev.getGattClient().equals(gatt)) {
//mProvServerDev.setConnectionState(PeerDevice.STATE_CONNECTED);
}
}
}
if (mProxyDev != null) {
if (mProxyDev.getGattClient() != null) {
if (mProxyDev.getGattClient().equals(gatt)) {
//mProxyDev.setConnectionState(PeerDevice.STATE_CONNECTED);
}
}
}
if (D) {
Log.i(TAG, "Connected to GATT server.");
}
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
boolean retry = false;
if (mProvServerDev != null) {
if (mProvServerDev.getGattClient() != null) {
if (mProvServerDev.getGattClient().equals(gatt)) {
if (mProvServerDev.getConnectionState() == PeerDevice.STATE_CONNECTING) {
Log.i(TAG, "connect failed, try again, status="+status);
gatt.connect();
retry = true;
} else {
mProvServerDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
gatt.close();
mProvServerDev = null;
}
}
}
}
if (mProxyDev != null) {
if (mProxyDev.getGattClient() != null) {
if (mProxyDev.getGattClient().equals(gatt)) {
if (mProxyDev.getConnectionState() == PeerDevice.STATE_CONNECTING) {
Log.i(TAG, "connect failed, try again, status="+status);
gatt.connect();
retry = true;
} else {
mProxyDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
gatt.close();
mProxyDev = null;
}
}
}
}
if (retry == false) {
if (D) {
Log.i(TAG, "Disconnected from GATT server.");
}
String strAddr=gatt.getDevice().getAddress();
byte[] addr = stringToAddress(strAddr);
connectionChangedNative(addr, false, status);
}
}
}