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


Java BluetoothGattDescriptor.getValue方法代碼示例

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


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

示例1: getView

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public View getView(int position, View view, ViewGroup parent) {
    final ViewHolder viewHolder;
    // General ListView optimization code.
    if (view == null) {
        view = mInflater.inflate(R.layout.list_item, null);
        viewHolder = new ViewHolder();
        viewHolder.descUuid = (TextView) view.findViewById(R.id.tv_item2);
        viewHolder.descValue = (TextView) view.findViewById(R.id.tv_item1);
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    BluetoothGattDescriptor desc = (BluetoothGattDescriptor) getItem(position);
    viewHolder.descUuid.setText("uuid: " + desc.getUuid().toString().substring(4, 8));
    if (desc.getValue() != null && desc.getValue().length > 0) {
        viewHolder.descValue.setText("Name:" + GattAttributeResolver.getAttributeName(desc.getUuid().toString(), mContext.getString(R.string.unknown))
                + "\n" + "Value:" + ByteUtils.byteArrayToHexString(desc.getValue()));
    } else {
        viewHolder.descValue.setText("Name:" + GattAttributeResolver.getAttributeName(desc.getUuid().toString(), mContext.getString(R.string.unknown)));
    }
    return view;
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:25,代碼來源:DescListAdapter.java

示例2: onCharacteristicChanged

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public final void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
	final String data = ParserUtils.parse(characteristic);

	if (isBatteryLevelCharacteristic(characteristic)) {
		Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
		final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
		Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
		mCallbacks.onBatteryValueReceived(batteryValue);
	} else {
		final BluetoothGattDescriptor cccd = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
		final boolean notifications = cccd == null || cccd.getValue() == null || cccd.getValue().length != 2 || cccd.getValue()[0] == 0x01;

		if (notifications) {
			Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
			onCharacteristicNotified(gatt, characteristic);
		} else { // indications
			Logger.i(mLogSession, "Indication received from " + characteristic.getUuid() + ", value: " + data);
			onCharacteristicIndicated(gatt, characteristic);
		}
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:23,代碼來源:BleManager.java

示例3: onDescriptorRead

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public void onDescriptorRead(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        if (CLIENT_CHARACTERISTIC_CONFIG.equals(descriptor.getUuid())) {
            if (SERVICE_CHANGED_UUID.equals(descriptor.getCharacteristic().getUuid())) {
                // We have enabled indications for the Service Changed characteristic
                mServiceChangedIndicationsEnabled = descriptor.getValue()[0] == 2;
                mRequestCompleted = true;
            }
        }
    } else {
        loge("Descriptor read error: " + status);
        mError = ERROR_CONNECTION_MASK | status;
    }
    // Notify waiting thread
    synchronized (mLock) {
        mLock.notifyAll();
    }
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:20,代碼來源:DfuBaseService.java

示例4: onDescriptorWrite

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

    if (status == BluetoothGatt.GATT_SUCCESS) {
        if (CLIENT_CHARACTERISTIC_CONFIG.equals(descriptor.getUuid())) {
            if (SERVICE_CHANGED_UUID.equals(descriptor.getCharacteristic().getUuid())) {
                // We have enabled indications for the Service Changed characteristic
                mServiceChangedIndicationsEnabled = descriptor.getValue()[0] == 2;
            } else {
                // We have enabled notifications for this characteristic
                mNotificationsEnabled = descriptor.getValue()[0] == 1;
            }
        }
    } else {
        loge("Descriptor write error: " + status);
        mError = ERROR_CONNECTION_MASK | status;
    }
    // Notify waiting thread
    synchronized (mLock) {
        mLock.notifyAll();
    }
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:23,代碼來源:DfuBaseService.java

示例5: getDescriptorValue

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public byte[] getDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return descriptor.getValue();
}
 
開發者ID:MB3hel,項目名稱:Quick-Bluetooth-LE,代碼行數:13,代碼來源:BLEServer.java

示例6: getDescriptorValueString

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public String getDescriptorValueString(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return new String(descriptor.getValue());
}
 
開發者ID:MB3hel,項目名稱:Quick-Bluetooth-LE,代碼行數:13,代碼來源:BLEServer.java

示例7: getDescriptorValue

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public byte[] getDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return descriptor.getValue();
}
 
開發者ID:MB3hel,項目名稱:Quick-Bluetooth-LE,代碼行數:13,代碼來源:BLEClient.java

示例8: getDescriptorValueString

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public String getDescriptorValueString(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid){
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return null;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return null;
	return new String(descriptor.getValue());
}
 
開發者ID:MB3hel,項目名稱:Quick-Bluetooth-LE,代碼行數:13,代碼來源:BLEClient.java

示例9: onDescriptorWrite

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
@Override
public final void onDescriptorWrite(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
	if (status == BluetoothGatt.GATT_SUCCESS) {
		Logger.i(mLogSession, "Data written to descr. " + descriptor.getUuid() + ", value: " + ParserUtils.parse(descriptor));

		if (isServiceChangedCCCD(descriptor)) {
			Logger.a(mLogSession, "Service Changed notifications enabled");
			if (!readBatteryLevel())
				nextRequest();
		} else if (isBatteryLevelCCCD(descriptor)) {
			final byte[] value = descriptor.getValue();
			if (value != null && value.length > 0 && value[0] == 0x01) {
				Logger.a(mLogSession, "Battery Level notifications enabled");
				nextRequest();
			} else
				Logger.a(mLogSession, "Battery Level notifications disabled");
		} else {
			nextRequest();
		}
	} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
		if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
			DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
			mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
		}
	} else {
		DebugLogger.e(TAG, "onDescriptorWrite error " + status);
		onError(ERROR_WRITE_DESCRIPTOR, status);
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:30,代碼來源:BleManager.java

示例10: isNotificationEnabled

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public boolean isNotificationEnabled(String mac, BluetoothGattCharacteristic characteristic) {
    BluetoothGatt bluetoothGatt = checkAndGetGattItem(mac);
    boolean result = false;
    if (bluetoothGatt != null) {
        BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(GattInfo.CLIENT_CHARACTERISTIC_CONFIG);
        if (clientConfig != null) {
            result = clientConfig.getValue() == BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
        }
    }
    return result;
}
 
開發者ID:UDOOboard,項目名稱:UDOOBluLib-android,代碼行數:12,代碼來源:UdooBluService.java

示例11: asWritableMap

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
public WritableMap asWritableMap(BluetoothGatt gatt) {

		WritableMap map = asWritableMap();

		WritableArray servicesArray = Arguments.createArray();
		WritableArray characteristicsArray = Arguments.createArray();

		if (connected && gatt != null) {
			for (BluetoothGattService service : gatt.getServices()) {
				WritableMap serviceMap = Arguments.createMap();
				serviceMap.putString("uuid", UUIDHelper.uuidToString(service.getUuid()));



				for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
					WritableMap characteristicsMap = Arguments.createMap();

					characteristicsMap.putString("service", UUIDHelper.uuidToString(service.getUuid()));
					characteristicsMap.putString("characteristic", UUIDHelper.uuidToString(characteristic.getUuid()));

					characteristicsMap.putMap("properties", Helper.decodeProperties(characteristic));

					if (characteristic.getPermissions() > 0) {
						characteristicsMap.putMap("permissions", Helper.decodePermissions(characteristic));
					}


					WritableArray descriptorsArray = Arguments.createArray();

					for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
						WritableMap descriptorMap = Arguments.createMap();
						descriptorMap.putString("uuid", UUIDHelper.uuidToString(descriptor.getUuid()));
						if (descriptor.getValue() != null)
							descriptorMap.putString("value", Base64.encodeToString(descriptor.getValue(), Base64.NO_WRAP));
						else
							descriptorMap.putString("value", null);

						if (descriptor.getPermissions() > 0) {
							descriptorMap.putMap("permissions", Helper.decodePermissions(descriptor));
						}
						descriptorsArray.pushMap(descriptorMap);
					}
					if (descriptorsArray.size() > 0) {
						characteristicsMap.putArray("descriptors", descriptorsArray);
					}
					characteristicsArray.pushMap(characteristicsMap);
				}
				servicesArray.pushMap(serviceMap);
			}
			map.putArray("services", servicesArray);
			map.putArray("characteristics", characteristicsArray);
		}

		return map;
	}
 
開發者ID:lenglengiOS,項目名稱:react-native-blue-manager,代碼行數:56,代碼來源:Peripheral.java

示例12: displayGattServices

import android.bluetooth.BluetoothGattDescriptor; //導入方法依賴的package包/類
private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null) return;

    for (BluetoothGattService gattService : gattServices) {
        //-----Service的字段信息-----//
        int type = gattService.getType();
        Log.e(TAG,"-->service type:"+Utils.getServiceType(type));
        Log.e(TAG,"-->includedServices size:"+gattService.getIncludedServices().size());
        Log.e(TAG,"-->service uuid:"+gattService.getUuid());

        //-----Characteristics的字段信息-----//
        List<BluetoothGattCharacteristic> gattCharacteristics =gattService.getCharacteristics();
        for (final BluetoothGattCharacteristic  gattCharacteristic: gattCharacteristics) {
            Log.e(TAG,"---->char uuid:"+gattCharacteristic.getUuid());

            int permission = gattCharacteristic.getPermissions();
            Log.e(TAG,"---->char permission:"+Utils.getCharPermission(permission));

            int property = gattCharacteristic.getProperties();
            Log.e(TAG,"---->char property:"+Utils.getCharPropertie(property));

            byte[] data = gattCharacteristic.getValue();
            if (data != null && data.length > 0) {
                Log.e(TAG,"---->char value:"+new String(data));
            }

            if(gattCharacteristic.getUuid().toString().equals(UUID_RESPONSE)) {
                ResponseCharac = gattCharacteristic;
            }


            //UUID_KEY_DATA是可以跟藍牙模塊串口通信的Characteristic
            if(gattCharacteristic.getUuid().toString().equals(UUID_REQUEST)){
                //測試讀取當前Characteristic數據,會觸發mOnDataAvailable.onCharacteristicRead()
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mBLE.readCharacteristic(gattCharacteristic);
                        mHandler.postDelayed(this, 500);

                        mBLE.readRemoteRssi();

                        //BluetoothGattDescriptor descriptor = gattCharacteristic.getDescriptor(HD_Profile.UUID_CHAR_NOTIFY_DIS)
                    }
                }, 500);

                //接受Characteristic被寫的通知,收到藍牙模塊的數據後會觸發mOnDataAvailable.onCharacteristicWrite()
                mBLE.setCharacteristicNotification(gattCharacteristic, true);

                //設置數據內容
                //gattCharacteristic.setValue("hi");
                //往藍牙模塊寫入數據
              // mBLE.writeCharacteristic(gattCharacteristic);
            }




            //-----Descriptors的字段信息-----//
            List<BluetoothGattDescriptor> gattDescriptors = gattCharacteristic.getDescriptors();
            for (BluetoothGattDescriptor gattDescriptor : gattDescriptors) {
                Log.e(TAG, "-------->desc uuid:" + gattDescriptor.getUuid());
                int descPermission = gattDescriptor.getPermissions();
                Log.e(TAG,"-------->desc permission:"+ Utils.getDescPermission(descPermission));

                byte[] desData = gattDescriptor.getValue();
                if (desData != null && desData.length > 0) {
                    Log.e(TAG, "-------->desc value:"+ new String(desData));
                }
            }
        }
    }//

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

示例13: start

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


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