当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGatt.requestMtu方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:22,代码来源:BTLEAdt.java

示例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;
    }
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:39,代码来源:BTLEAdt.java

示例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);
}
    	}
    }
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:70,代码来源:JniCallbacks.java


注:本文中的android.bluetooth.BluetoothGatt.requestMtu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。