當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGatt.close方法代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothGatt.close方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGatt.close方法的具體用法?Java BluetoothGatt.close怎麽用?Java BluetoothGatt.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.bluetooth.BluetoothGatt的用法示例。


在下文中一共展示了BluetoothGatt.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        for(BluetoothGattService service : gatt.getServices()){
            Log.d(mTAG, "service: " + service.getUuid().toString());
        }
        //Log.d(mTAG, "mGattMiFloraService: " + UUID_MI_FLORA_SERVICE_ID.toString());
        mGattMiFloraService = gatt.getService(UUID_MI_FLORA_SERVICE_ID);
        if(mGattMiFloraService != null){
            boolean rs = gatt.readCharacteristic(mGattMiFloraService.getCharacteristic(UUID_MI_FLORA_FIRMWARE));
            if(!rs){
                Log.i(mTAG, "Can't read mGattMiFloraFwCharacteristic");
            }
        }
    }
    else{
        gatt.close();
        mIsConnecting = false;
    }
}
 
開發者ID:dmtan90,項目名稱:Sense-Hub-Android-Things,代碼行數:21,代碼來源:MiFloraSensorEntity.java

示例2: onCharacteristicChanged

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    Log.d(mTAG, "onCharacteristicChanged");
    byte[] mValue = characteristic.getValue();
    if(characteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
        mAirTemperature = (mValue[0] << 8 | mValue[1])/10;
        gatt.setCharacteristicNotification(characteristic, false);
        List<BluetoothGattCharacteristic> lstChars = mGattnRF51822Service.getCharacteristics();
        for(BluetoothGattCharacteristic mCharacteristic : lstChars){
            List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
            BluetoothGattDescriptor mGattnRF51822Descriptor = mCharacteristic.getDescriptor(UUID_nRF51822_DESCRIPTOR_ID);
            if(mGattnRF51822Descriptor != null && mCharacteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
                gatt.setCharacteristicNotification(mCharacteristic, true);
                byte[] mDesValue = {0x01, 0x00};
                mGattnRF51822Descriptor.setValue(mDesValue);
                gatt.writeDescriptor(mGattnRF51822Descriptor);
            }
        }
    }
    else if(characteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
        mLight = (mValue[0] << 8 | mValue[1]);
        gatt.close();
        Log.d(mTAG, "onCharacteristicChanged data=" + getData());
        mIsConnecting = false;
    }
}
 
開發者ID:dmtan90,項目名稱:Sense-Hub-Android-Things,代碼行數:27,代碼來源:nRF51822SensorEntity.java

示例3: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        mGattnTitagBatteryService = gatt.getService(UUID_TITAG_BATTERY_SERVICE);
        mGattnTitagTempHumidityService = gatt.getService(UUID_TITAG_AIR_TEMP_HUMIDITY_SERVICE);
        mGattnTitagLightService = gatt.getService(UUID_TITAG_LIGHT_SERVICE);
        if(mGattnTitagBatteryService != null){
            gatt.readCharacteristic(mGattnTitagBatteryService.getCharacteristic(UUID_TITAG_GET_BATTERY));
        }
    }
    else{
        gatt.close();
        mIsConnecting = false;
    }
}
 
開發者ID:dmtan90,項目名稱:Sense-Hub-Android-Things,代碼行數:16,代碼來源:TitagSensorEntity.java

示例4: onOWStateChangedToDisconnected

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
private void onOWStateChangedToDisconnected(BluetoothGatt gatt) {
    updateLog("We got disconnected from our Device: " + gatt.getDevice().getAddress());
    mainActivity.deviceConnectedTimer(false);
    mOWDevice.isConnected.set(false);
    App.INSTANCE.releaseWakeLock();
    mScanResults.clear();

    if (App.INSTANCE.getSharedPreferences().shouldAutoReconnect()) {
        updateLog("Attempting to Reconnect to " + mOWDevice.deviceMacAddress.get());
        BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mOWDevice.deviceMacAddress.get());
        connectToDevice(device);
        //scanLeDevice(true);
    } else {
        gatt.close();

    }
    mainActivity.invalidateOptionsMenu();
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:19,代碼來源:BluetoothUtilImpl.java

示例5: onStep

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * Will handle cleaning up resources and starting the discovery again if the step was not
 * successful
 *
 * @param gatt The {@link BluetoothGatt} to clean up
 * @param success boolean indicating whether or not step was successful
 */
private void onStep(BluetoothGatt gatt, boolean success) {
    // Close the BluetoothGatt, update GUI and start scanning again if step was not
    // successful
    if (!success) {
        gatt.close();
        bluetoothGatt = null;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                deviceAddressTextView.setText("");
            }
        });
        startDiscovery();
    }
}
 
開發者ID:SPINremote,項目名稱:sdc-1-quickstart-android,代碼行數:23,代碼來源:MainActivity.java

示例6: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    Log.d(mTAG, "onServicesDiscovered");
    if(status == BluetoothGatt.GATT_SUCCESS){
        mGattnRF51822Service = gatt.getService(UUID_nRF51822_SERVICE_ID);
        if(mGattnRF51822Service != null){
            List<BluetoothGattCharacteristic> lstChars = mGattnRF51822Service.getCharacteristics();
            for(BluetoothGattCharacteristic mCharacteristic : lstChars){
                List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
                BluetoothGattDescriptor mGattnRF51822Descriptor = mCharacteristic.getDescriptor(UUID_nRF51822_DESCRIPTOR_ID);
                if(mGattnRF51822Descriptor != null && mCharacteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
                    gatt.setCharacteristicNotification(mCharacteristic, true);
                    byte[] mValue = {0x01, 0x00};
                    mGattnRF51822Descriptor.setValue(mValue);
                    gatt.writeDescriptor(mGattnRF51822Descriptor);
                }
            }
        }
    }
    else{
        gatt.close();
        mIsConnecting = false;
    }
}
 
開發者ID:dmtan90,項目名稱:Sense-Hub-Android-Things,代碼行數:25,代碼來源:nRF51822SensorEntity.java

示例7: close

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * 關閉藍牙連接,會釋放BluetoothGatt持有的所有資源
 * @param address
 */
public boolean close(String address) {
    if (!isEmpty(address) && gattMap.containsKey(address)){
        Logger.w( "close gatt server " + address);
        BluetoothGatt mBluetoothGatt = gattMap.get(address);
        mBluetoothGatt.close();
        gattMap.remove(address);
        updateConnectState(address, ConnectState.NORMAL);
        return true;
    }
    return false;
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:16,代碼來源:ConnectRequestQueue.java

示例8: close

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * close bluetooth, release resource
 * @param address
 */
public boolean close(String address) {
    if (!isEmpty(address) && gattMap.containsKey(address)){
        Logger.w("close gatt server " + address);
        BluetoothGatt mBluetoothGatt = gattMap.get(address);
        mBluetoothGatt.close();
        gattMap.remove(address);
        updateConnectStateListener(address, ConnectState.NORMAL);
        return true;
    }
    return false;
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:16,代碼來源:BluetoothConnectManager.java

示例9: onConnectionStateChange

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    boolean didConnect = false;
    NeatleLogger.d("onConnectionStateChange status: " + status + " newState:" + newState);
    if (newState == BluetoothGatt.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
        didConnect = gatt.discoverServices();
    }

    if (!didConnect) {
        gatt.close();
        connectionFailed(status);
    } else {
        connectionSuccess();
    }
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:16,代碼來源:Device.java

示例10: close

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * Closes the GATT device and cleans up.
 *
 * @param gatt the GATT device to be closed
 */
private void close(final BluetoothGatt gatt) {
    logi("Cleaning up...");
    sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.close()");
    gatt.disconnect();
    gatt.close();
    mConnectionState = STATE_CLOSED;
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:13,代碼來源:DfuBaseService.java

示例11: closeBluetoothGatt

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * 關閉GATT連接
 * @param gatt
 */
public static void closeBluetoothGatt(BluetoothGatt gatt) {
    if (gatt != null) {
        gatt.disconnect();
        refreshDeviceCache(gatt);
        gatt.close();
    }
}
 
開發者ID:qiu-yongheng,項目名稱:Bluetooth_BLE,代碼行數:12,代碼來源:BluetoothUtil.java

示例12: close

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * After using a given BLE device, the app must call this method to ensure resources are released properly.
 */
public void close() {
    Set<String> macs = mBluetoothGatts.keySet();
    for (String deviceMac : macs) {
        BluetoothGatt bluetoothGatt = mBluetoothGatts.get(deviceMac);
        if (bluetoothGatt != null) {
            bluetoothGatt.close();
            mBluetoothGatts.remove(deviceMac);
        }
    }
}
 
開發者ID:UDOOboard,項目名稱:UDOOBluLib-android,代碼行數:14,代碼來源:UdooBluService.java

示例13: onDisconnected

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
private void onDisconnected(BluetoothGatt gatt) {
  gatt.close();
  BlePair pair = bluetoothGatt.get(gatt.getDevice().getAddress());
  if (pair != null) {
    bluetoothGatt.remove(gatt.getDevice().getAddress());
    sendBroadcast(
        new Intent(DEVICE_DISCONNECTED)
            .putExtra(DEVICE_ADDRESS, gatt.getDevice().getAddress())
    );
  }
  if (bluetoothGatt.size() == 0) {
    stopSelf();
  }
}
 
開發者ID:drfonfon,項目名稱:ITagAntiLost,代碼行數:15,代碼來源:BleService.java

示例14: onConnectionStateChange

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);

    if(DEBUG) {
        logi("BluetoothGattCallback.onConnectionStateChange() :: start : status = " + status + " newState = " +
                "" + newState);
    }

    int state = BLE_DISCONNECTED;
    int error = 0;

    boolean gattForceClosed = false;

    switch(status) {
        case BluetoothGatt.GATT_SUCCESS: {
            if(newState == BluetoothProfile.STATE_CONNECTED) {
                state = BLE_CONNECTED;
            } else if(newState == BluetoothProfile.STATE_DISCONNECTED) {
                state = BLE_DISCONNECTED;
                if(gatt != null) {
                    if(DEBUG) {
                        logi("onConnectionStateChange() :: gatt != null : closing gatt");
                    }

                    gatt.disconnect();
                    gatt.close();
                    gattForceClosed = true;
                    if(BLEManager.this.gatt.getDevice().getAddress().equals(gatt.getDevice().getAddress())) {
                        BLEManager.this.gatt = null;
                    }
                }
            }
        }
        break;
        default:
            Log.e(TAG, "Connection error: " + GattError.parseConnectionError(status));
            break;
    }

    if(status != BluetoothGatt.GATT_SUCCESS) {
        state = BLE_DISCONNECTED;
        error = BLE_ERROR_FAIL;
    }

    synchronized(locker) {
        if(inBleOp == OP_CONNECT) {
            if(DEBUG) {
                logi("BluetoothGattCallback.onConnectionStateChange() :: inBleOp == OP_CONNECT");
            }

            if(state != (bleState & BLE_CONNECTED)) {
                bleState = state;
            }
            callbackCompleted = true;
            BLEManager.this.error = error;
            extendedError = status;
            locker.notify();
        } else {
            if(DEBUG) {
                logi("onConnectionStateChange() :: inBleOp != OP_CONNECT");
            }

            bleState = state;
            unexpectedDisconnectionListener.handleConnectionEvent(bleState, gattForceClosed);
        }

        if(DEBUG) {
            logi("BluetoothGattCallback.onConnectionStateChange() :: end");
        }
    }
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:73,代碼來源:BLEManager.java

示例15: 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.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。