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


Java BluetoothGattDescriptor類代碼示例

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


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

示例1: onCharacteristicChanged

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的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

示例2: onDescriptorWrite

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
    Log.i(TAG, "onDescriptorWrite: " + status);
    descriptorWriteQueue.remove();  //pop the item that we just finishing writing
    //if there is more to write, do it!
    if(descriptorWriteQueue.size() > 0) {
        gatt.writeDescriptor(descriptorWriteQueue.element());
    } else if(characteristicReadQueue.size() > 0) {
        gatt.readCharacteristic(characteristicReadQueue.element());
    }
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:12,代碼來源:BluetoothUtilImpl.java

示例3: handleDescriptorReadCallback

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
/**
 * 讀描述符
 * @param bleCallback
 */
private void handleDescriptorReadCallback(final BleDescriptorCallback bleCallback) {
    if (bleCallback != null) {
        listenAndTimer(bleCallback, MSG_READ_DES, new BluetoothGattCallback() {
            AtomicBoolean msgRemoved = new AtomicBoolean(false);

            @Override
            public void onDescriptorRead(BluetoothGatt gatt,
                                         BluetoothGattDescriptor descriptor, int status) {
                if (!msgRemoved.getAndSet(true)) {
                    handler.removeMessages(MSG_READ_DES, this);
                }
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    bleCallback.onSuccess(descriptor);
                } else {
                    bleCallback.onFailure(new GattException(status));
                }
            }
        });
    }
}
 
開發者ID:qiu-yongheng,項目名稱:Bluetooth_BLE,代碼行數:25,代碼來源:LiteBleConnector.java

示例4: getSupportedGattServices

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
public List<BluetoothGattService> getSupportedGattServices() {
    if (mBluetoothGatt == null) {
        return null;
    }

    List<BluetoothGattService> gattServices = mBluetoothGatt.getServices();

    for (BluetoothGattService gattService : gattServices) {
        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            String uuid = gattCharacteristic.getUuid().toString();
            if(uuid.equalsIgnoreCase(UUID_NOTIFY.toString())){
                mNotifyCharacteristic = gattCharacteristic;
                mBluetoothGatt.setCharacteristicNotification(gattCharacteristic, true);
                ULog.i("setCharacteristicNotification : " + uuid);
                BluetoothGattDescriptor descriptor = gattCharacteristic
                        .getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                mBluetoothGatt.writeDescriptor(descriptor);
            }
        }
    }
    return gattServices;
}
 
開發者ID:WillFlower,項目名稱:BluetoothCtrl,代碼行數:25,代碼來源:BluetoothLeService.java

示例5: setCharacteristicNotification

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
/**
 * Enables or disables notification on a give characteristic.
 *
 * @param characteristic Characteristic to act on.
 * @param enabled If true, enable notification.  False otherwise.
 */
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
                                          boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
    for(BluetoothGattDescriptor dp:descriptors){
        dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(dp);
    }




}
 
開發者ID:haoyifan,項目名稱:BLE-PEPS,代碼行數:25,代碼來源:BluetoothLeClass.java

示例6: BLEServer

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
public BLEServer(Context context, BLEServerDelegate delegate){
	this.context = context;
	this.delegate = delegate;
	if(this.delegate == null){
		this.delegate = new BLEServerDelegate() {
			@Override
			public void onAdvertise(AdvertiseError error) {}
			@Override
			public void onDeviceConnected(BluetoothDevice device) {}
			@Override
			public void onDeviceDisconnected(BluetoothDevice device) {}
			@Override
			public void onCharacteristicChangedServer(BluetoothGattCharacteristic characteristic) {}
			@Override
			public void onDescriptorChanged(BluetoothGattDescriptor descriptor) {}
		};
	}
}
 
開發者ID:MB3hel,項目名稱:Quick-Bluetooth-LE,代碼行數:19,代碼來源:BLEServer.java

示例7: onDescriptorReadRequest

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
@Override
public void onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset,
                                    BluetoothGattDescriptor descriptor) {
    if (TimeProfile.CLIENT_CONFIG.equals(descriptor.getUuid())) {
        Log.d(TAG, "Config descriptor read");
        byte[] returnValue;
        if (mRegisteredDevices.contains(device)) {
            returnValue = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
        } else {
            returnValue = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
        }
        mBluetoothGattServer.sendResponse(device,
                requestId,
                BluetoothGatt.GATT_FAILURE,
                0,
                returnValue);
    } else {
        Log.w(TAG, "Unknown descriptor read request");
        mBluetoothGattServer.sendResponse(device,
                requestId,
                BluetoothGatt.GATT_FAILURE,
                0,
                null);
    }
}
 
開發者ID:androidthings,項目名稱:sample-bluetooth-le-gattserver,代碼行數:26,代碼來源:GattServerActivity.java

示例8: setCharacteristicNotification

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
private void setCharacteristicNotification(
    @NonNull BluetoothGatt bluetoothgatt,
    @NonNull BluetoothGattCharacteristic bluetoothgattcharacteristic,
    boolean flag
) {
  bluetoothgatt.setCharacteristicNotification(bluetoothgattcharacteristic, flag);
  if (FIND_ME_CHARACTERISTIC.equals(bluetoothgattcharacteristic.getUuid())) {
    BluetoothGattDescriptor descriptor = bluetoothgattcharacteristic.getDescriptor(
        CLIENT_CHARACTERISTIC_CONFIG
    );
    if (descriptor != null) {
      descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
      bluetoothgatt.writeDescriptor(descriptor);
    }
  }
}
 
開發者ID:drfonfon,項目名稱:ITagAntiLost,代碼行數:17,代碼來源:BleService.java

示例9: setCharacteristicNotification

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
/**
 * Enable or disable notifications/indications for a given characteristic.
 *
 * 是否允許刷新特征碼
 *
 * <p>Once notifications are enabled for a characteristic, a
 * {@link BluetoothGattCallback#onCharacteristicChanged} callback will be
 * triggered if the remote device indicates that the given characteristic
 * has changed.
 *
 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
 *
 * @param characteristic The characteristic for which to enable notifications
 * @param enable         Set to true to enable notifications/indications
 * @return true, if the requested notification status was set successfully
 */
public boolean setCharacteristicNotification(BluetoothGatt gatt,
                                             BluetoothGattCharacteristic characteristic,
                                             boolean enable) {
    if (gatt != null && characteristic != null) {
        BleLog.i(TAG, "Characteristic set notification value: " + enable);
        /** 是否允許刷新特征碼獲取數據 */
        boolean success = gatt.setCharacteristicNotification(characteristic, enable);

        // This is specific to Heart Rate Measurement.(心率測量專用)
        if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
            BleLog.i(TAG, "Heart Rate Measurement set [descriptor] notification value: " + enable);
            BluetoothGattDescriptor descriptor = characteristic
                    .getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));

            // 向描述符中寫入 'ENABLE_NOTIFICATION_VALUE'
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descriptor);
        }
        return success;
    }
    return false;
}
 
開發者ID:qiu-yongheng,項目名稱:Bluetooth_BLE,代碼行數:39,代碼來源:LiteBleConnector.java

示例10: onDescriptorWriteRequest

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
@Override
public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
    if (DESCRIPTOR_CONFIG.equals(descriptor.getUuid())) {
        if (Arrays.equals(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, value)) {
            Log.d(TAG, "Subscribe device to notifications: " + device);
            mRegisteredDevices.add(device);
        } else if (Arrays.equals(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE, value)) {
            Log.d(TAG, "Unsubscribe device from notifications: " + device);
            mRegisteredDevices.remove(device);
        }

        if (responseNeeded) {
            mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null);
        }
    } else {
        Log.w(TAG, "Unknown descriptor write request");
        if (responseNeeded) {
            mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_FAILURE, 0, null);
        }
    }
}
 
開發者ID:Nilhcem,項目名稱:blefun-androidthings,代碼行數:22,代碼來源:GattServer.java

示例11: enableNotifications

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
@Override
public final boolean enableNotifications(final BluetoothGattCharacteristic characteristic) {
	final BluetoothGatt gatt = mBluetoothGatt;
	if (gatt == null || characteristic == null)
		return false;

	// Check characteristic property
	final int properties = characteristic.getProperties();
	if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0)
		return false;

	gatt.setCharacteristicNotification(characteristic, true);
	final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
	if (descriptor != null) {
		descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
		return gatt.writeDescriptor(descriptor);
	}
	return false;
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:20,代碼來源:BleManager.java

示例12: enableIndications

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
@Override
public final boolean enableIndications(final BluetoothGattCharacteristic characteristic) {
	final BluetoothGatt gatt = mBluetoothGatt;
	if (gatt == null || characteristic == null)
		return false;

	// Check characteristic property
	final int properties = characteristic.getProperties();
	if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) == 0)
		return false;

	gatt.setCharacteristicNotification(characteristic, true);
	final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
	if (descriptor != null) {
		descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
		return gatt.writeDescriptor(descriptor);
	}
	return false;
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:20,代碼來源:BleManager.java

示例13: onDescriptorWriteRequest

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
@Override
public void onDescriptorWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattDescriptor descriptor, final boolean preparedWrite, final boolean responseNeeded, final int offset, final byte[] value) {
    super.onDescriptorWriteRequest(device, requestId, descriptor, preparedWrite, responseNeeded, offset, value);
    Log.d(TAG, "onDescriptorWriteRequest descriptor: " + descriptor.getUuid() + ", value: " + Arrays.toString(value) + ", responseNeeded: " + responseNeeded + ", preparedWrite: " + preparedWrite);

    descriptor.setValue(value);

    if (responseNeeded) {
        if (BleUuidUtils.matches(DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION, descriptor.getUuid())) {
            // send empty
            if (gattServer != null) {
                gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, EMPTY_BYTES);
            }
        }
    }
}
 
開發者ID:kshoji,項目名稱:BLE-HID-Peripheral-for-Android,代碼行數:17,代碼來源:HidPeripheral.java

示例14: enableNotifications

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的package包/類
/**
 * Enables notifications on given characteristic
 *
 * @return true is the request has been sent, false if one of the arguments was <code>null</code> or the characteristic does not have the CCCD.
 */
protected final boolean enableNotifications(final BluetoothGattCharacteristic characteristic) {
	final BluetoothGatt gatt = mBluetoothGatt;
	if (gatt == null || characteristic == null)
		return false;

	// Check characteristic property
	final int properties = characteristic.getProperties();
	if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0)
		return false;

	Logger.d(mLogSession, "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
	gatt.setCharacteristicNotification(characteristic, true);
	final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
	if (descriptor != null) {
		descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
		Logger.v(mLogSession, "Enabling notifications for " + characteristic.getUuid());
		Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x01-00)");
		return gatt.writeDescriptor(descriptor);
	}
	return false;
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:27,代碼來源:BleManager.java

示例15: onServicesDiscovered

import android.bluetooth.BluetoothGattDescriptor; //導入依賴的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


注:本文中的android.bluetooth.BluetoothGattDescriptor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。