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


Java BluetoothGatt.setCharacteristicNotification方法代碼示例

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


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

示例1: 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

示例2: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        boolean connected = false;

        BluetoothGattService service = gatt.getService(SERVICE_UUID);
        if (service != null) {
            BluetoothGattCharacteristic characteristic = service.getCharacteristic(CHARACTERISTIC_COUNTER_UUID);
            if (characteristic != null) {
                gatt.setCharacteristicNotification(characteristic, true);

                BluetoothGattDescriptor descriptor = characteristic.getDescriptor(DESCRIPTOR_CONFIG);
                if (descriptor != null) {
                    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                    connected = gatt.writeDescriptor(descriptor);
                }
            }
        }
        mListener.onConnected(connected);
    } else {
        Log.w(TAG, "onServicesDiscovered received: " + status);
    }
}
 
開發者ID:Nilhcem,項目名稱:blefun-androidthings,代碼行數:24,代碼來源:GattClient.java

示例3: enableNotifications

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

示例4: enableIndications

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

示例5: enableNotifications

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

示例6: enableIndications

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * Enables indications 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 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;

	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_INDICATION_VALUE);
		Logger.v(mLogSession, "Enabling indications for " + characteristic.getUuid());
		Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x02-00)");
		return gatt.writeDescriptor(descriptor);
	}
	return false;
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:27,代碼來源:BleManager.java

示例7: 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

示例8: setCharacteristicNotification

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

示例9: setCharacteristicNotification

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

示例10: setBatteryNotifications

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * This method tries to enable notifications on the Battery Level characteristic.
 *
 * @param enable <code>true</code> to enable battery notifications, false to disable
 * @return true if request has been sent
 */
public boolean setBatteryNotifications(final boolean enable) {
	final BluetoothGatt gatt = mBluetoothGatt;
	if (gatt == null) {
		return false;
	}

	final BluetoothGattService batteryService = gatt.getService(BATTERY_SERVICE);
	if (batteryService == null)
		return false;

	final BluetoothGattCharacteristic batteryLevelCharacteristic = batteryService.getCharacteristic(BATTERY_LEVEL_CHARACTERISTIC);
	if (batteryLevelCharacteristic == null)
		return false;

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

	gatt.setCharacteristicNotification(batteryLevelCharacteristic, enable);
	final BluetoothGattDescriptor descriptor = batteryLevelCharacteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
	if (descriptor != null) {
		if (enable) {
			descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
			Logger.a(mLogSession, "Enabling battery level notifications...");
			Logger.v(mLogSession, "Enabling notifications for " + BATTERY_LEVEL_CHARACTERISTIC);
			Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x01-00)");
		} else {
			descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
			Logger.a(mLogSession, "Disabling battery level notifications...");
			Logger.v(mLogSession, "Disabling notifications for " + BATTERY_LEVEL_CHARACTERISTIC);
			Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x00-00)");
		}
		return gatt.writeDescriptor(descriptor);
	}
	return false;
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:44,代碼來源:BleManager.java

示例11: setNotifySensor

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
private void setNotifySensor(BluetoothGatt gatt) {
    BluetoothGattCharacteristic characteristic = gatt.getService(Globals.SNACH_SYSTEM_SERVICE_UUID).getCharacteristic(Globals.SNACH_SYSTEM_UART_TX_UUID);
    gatt.setCharacteristicNotification(characteristic, true);

    BluetoothGattDescriptor desc = characteristic.getDescriptor(Globals.SNACH_DESCRIPTOR_UUID);
    if(desc != null) {
        desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        Log.i("BLE", "Descriptor write: " + gatt.writeDescriptor(desc));
    }

}
 
開發者ID:ordsen,項目名稱:Snach-Android,代碼行數:12,代碼來源:BLEManager.java

示例12: onCharacteristicWrite

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * Callback indicating the result of a characteristic write operation.
 *
 * <p>If this callback is invoked while a reliable write transaction is
 * in progress, the value of the characteristic represents the value
 * reported by the remote device. An application should compare this
 * value to the desired value to be written. If the values don't match,
 * the application must abort the reliable write transaction.
 *
 * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic}
 * @param characteristic Characteristic that was written to the associated
 *                       remote device.
 * @param status The result of the write operation
 *               {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
 */
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    super.onCharacteristicWrite(gatt, characteristic, status);

    // boolean indicating whether or not the next step is successful, default is false
    boolean success = false;

    // Check if writing was successful and check what it was that we have written so we can
    // determine the next step
    if (status == BluetoothGatt.GATT_SUCCESS) {
        if (characteristic.getUuid().equals(COMMAND_CHARACTERISTIC_UUID)) {
            final byte[] value = characteristic.getValue();

            // Check if we have written the "Set LED color" command and go to the next step
            // (enabling action notification, step 6) if it is
            if ((value != null) && (value.length > 0)) {
                if (value[0] == (byte) 0x09) {
                    // Check if the SPIN Service is found
                    final BluetoothGattService spinService = gatt.getService(SPIN_SERVICE_UUID);
                    if (spinService != null) {
                        // Check if the Action Characteristic is found
                        final BluetoothGattCharacteristic actionCharacteristic
                                = spinService.getCharacteristic(ACTION_CHARACTERISTIC_UUID);
                        if (actionCharacteristic != null) {
                            // Enable notifications for the descriptor and store the result
                            final BluetoothGattDescriptor descriptor
                                    = actionCharacteristic.getDescriptor(UUID_CLIENT_CHARACTERISTIC_CONFIG);
                            if (descriptor != null) {
                                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

                                success = gatt.setCharacteristicNotification(actionCharacteristic, true)
                                        && gatt.writeDescriptor(descriptor);
                            }
                        }
                    }
                } else {
                    // There's no next step, set success to true
                    success = true;
                }
            }
        }
    }

    onStep(gatt, success);
}
 
開發者ID:SPINremote,項目名稱:sdc-1-quickstart-android,代碼行數:61,代碼來源:MainActivity.java

示例13: start

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
protected void start(Connection connection, BluetoothGatt gatt) {
    if (type == Type.UNSUBSCRIBE && connection.getCharacteristicsChangedListenerCount(characteristicUUID) > 0) {
        NeatleLogger.d("Won't unsubscribe on " + characteristicUUID + " since it has registered listeners");
        finish(CommandResult.createEmptySuccess(characteristicUUID));
        return;
    }

    BluetoothGattService service = gatt.getService(serviceUUID);
    if (service == null) {
        finish(CommandResult.createErrorResult(characteristicUUID, SERVICE_NOT_FOUND));
        return;
    }

    BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUUID);
    if (characteristic == null) {
        finish(CommandResult.createErrorResult(characteristicUUID, CHARACTERISTIC_NOT_FOUND));
        return;
    }

    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
    if (descriptor == null) {
        finish(CommandResult.createErrorResult(characteristicUUID, DESCRIPTOR_NOT_FOUND));
        return;
    }

    boolean turnOn;
    byte[] valueToWrite;
    switch (type) {
        case Type.SUBSCRIBE_INDICATION:
            NeatleLogger.d("Subscribing to indications on  " + characteristicUUID);
            valueToWrite = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;
            turnOn = true;
            break;
        case Type.SUBSCRIBE_NOTIFICATION:
            NeatleLogger.d("Subscribing to notifications on  " + characteristicUUID);
            valueToWrite = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
            turnOn = true;
            break;
        case Type.UNSUBSCRIBE:
            NeatleLogger.d("Unsubscribing from notifications/indications on  " + characteristicUUID);
            valueToWrite = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
            turnOn = false;
            break;
        default:
            throw new IllegalStateException();
    }

    byte[] descriptorValue = descriptor.getValue();
    if (Arrays.equals(descriptorValue, valueToWrite)) {
        NeatleLogger.d("No subscription changes needed - is at  " + valueToWrite[0] + " on " + characteristicUUID);
        finish(CommandResult.createEmptySuccess(characteristicUUID));
        return;
    }

    if (!gatt.setCharacteristicNotification(characteristic, turnOn)) {
        NeatleLogger.e("Failed to change characteristics notification flag on " + characteristicUUID);
        finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
        return;
    }

    descriptor.setValue(valueToWrite);
    NeatleLogger.e("Writing descriptor on " + characteristicUUID);
    if (!gatt.writeDescriptor(descriptor)) {
        NeatleLogger.e("Failed to write descriptor on " + characteristicUUID);
        finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
    }
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:69,代碼來源:SubscribeCommand.java

示例14: enableCCCD

import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
 * Enables or disables the notifications for given characteristic. This method is SYNCHRONOUS and wait until the
 * {@link android.bluetooth.BluetoothGattCallback#onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int)} will be called or the connection state will change from {@link #STATE_CONNECTED_AND_READY}. If
 * connection state will change, or an error will occur, an exception will be thrown.
 *
 * @param gatt           the GATT device
 * @param characteristic the characteristic to enable or disable notifications for
 * @param type           {@link #NOTIFICATIONS} or {@link #INDICATIONS}
 * @throws DfuException
 * @throws UploadAbortedException
 */
private void enableCCCD(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int type) throws DeviceDisconnectedException, DfuException, UploadAbortedException {
    final String debugString = type == NOTIFICATIONS ? "notifications" : "indications";
    if (mConnectionState != STATE_CONNECTED_AND_READY)
        throw new DeviceDisconnectedException("Unable to set " + debugString + " state", mConnectionState);

    mReceivedData = null;
    mError = 0;
    if ((type == NOTIFICATIONS && mNotificationsEnabled) || (type == INDICATIONS && mServiceChangedIndicationsEnabled))
        return;

    logi("Enabling " + debugString + "...");
    sendLogBroadcast(LOG_LEVEL_VERBOSE, "Enabling " + debugString + " for " + characteristic.getUuid());

    // enable notifications locally
    gatt.setCharacteristicNotification(characteristic, true);

    // enable notifications on the device
    final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
    descriptor.setValue(type == NOTIFICATIONS ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
    sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.writeDescriptor(" + descriptor.getUuid() + (type == NOTIFICATIONS ? ", value=0x01-00)" : ", value=0x02-00)"));
    gatt.writeDescriptor(descriptor);

    // We have to wait until device receives a response or an error occur
    try {
        synchronized (mLock) {
            while ((((type == NOTIFICATIONS && !mNotificationsEnabled) || (type == INDICATIONS && !mServiceChangedIndicationsEnabled))
                    && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
                mLock.wait();
        }
    } catch (final InterruptedException e) {
        loge("Sleeping interrupted", e);
    }

    if (mAborted)
        throw new UploadAbortedException();

    if (mError != 0)
        throw new DfuException("Unable to set " + debugString + " state", mError);

    if (mConnectionState != STATE_CONNECTED_AND_READY)
        throw new DeviceDisconnectedException("Unable to set " + debugString + " state", mConnectionState);
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:54,代碼來源:DfuBaseService.java


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