當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。