当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGattService.getCharacteristic方法代码示例

本文整理汇总了Java中android.bluetooth.BluetoothGattService.getCharacteristic方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGattService.getCharacteristic方法的具体用法?Java BluetoothGattService.getCharacteristic怎么用?Java BluetoothGattService.getCharacteristic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.bluetooth.BluetoothGattService的用法示例。


在下文中一共展示了BluetoothGattService.getCharacteristic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNotifications

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public void getNotifications(UUID service, UUID Characteristics) {
    if (!isConnectedToGatt || myGatBand == null) {
        Log.d(TAG, "Cant get notifications from BLE, not initialized.");
        return;
    }

    Log.d(TAG, "* Getting gatt service, UUID:" + service.toString());
    BluetoothGattService myGatService =
            myGatBand.getService(service/*Consts.UUID_SERVICE_MIBAND_SERVICE*/);
    if (myGatService != null) {
        Log.d(TAG, "* Getting gatt Characteristic. UUID: " + Characteristics.toString());

        BluetoothGattCharacteristic myGatChar
                = myGatService.getCharacteristic(Characteristics/*Consts.UUID_BUTTON_TOUCH*/);
        if (myGatChar != null) {
            Log.d(TAG, "* Statring listening");

            // second parametes is for starting\stopping the listener.
            boolean status =  myGatBand.setCharacteristicNotification(myGatChar, true);
            Log.d(TAG, "* Set notification status :" + status);
        }
    }
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:24,代码来源:BLEMiBand2Helper.java

示例2: actionGattServicesDiscovered

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
@Override
public void actionGattServicesDiscovered(Device device) {
	if (!device.isGBA400())
		return;
	if (bleService.getInternalBleService() == null) {
		Toast.makeText(context, context.getString(R.string.error_no_ble_service), Toast.LENGTH_SHORT).show();
		return;
	}
	List<BluetoothGattService> services = bleService.getInternalBleService().getSupportedGattServices();
	for (BluetoothGattService service : services) {
		if (service.getUuid().equals(ALERT_SERVICE_UUID)) {
			BluetoothGattCharacteristic gattCharacteristic = service.getCharacteristic(ALERT_CHARACTERISTIC_UUID);
			if (gattCharacteristic != null) {
				Log.i(TAG, "GBA-400 AlertService - Discovered!" + gattCharacteristic.getUuid().toString());
				alertGattCharacteristic = gattCharacteristic;
			}
		}
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:20,代码来源:Gba400AlertService.java

示例3: writeCharacteristic

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private void writeCharacteristic(String serviceGuid, String characteristic, int value, int type) {
    if(!isConnected()) {
        logi("writeCharacteristic() :: Not connected. Returning");
        return;
    }

    BluetoothGattService s = getService(UUID.fromString(serviceGuid));
    if(s == null) {
        logi("writeCharacteristic() :: Service not found");
        return;
    }

    BluetoothGattCharacteristic c = s.getCharacteristic(UUID.fromString(characteristic));
    if(c == null) {
        logi("writeCharacteristic() :: characteristic not found");
        return;
    }

    c.setValue(value, type, 0);
    int ret = writeCharacteristic(c);
    logi("writeCharacteristic() :: returns - " + ret);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:23,代码来源:BLEService.java

示例4: detectSensors

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private void detectSensors(String address, IReaderListener<byte[]> readerListener) {
    if (isBluManagerReady) {
        UUID servUuid = UDOOBLE.UUID_SENSORS_SERV;
        UUID dataUuid = UDOOBLE.UUID_SENSOR_DATA;

        BluetoothGattService serv = mUdooBluService.getService(address, servUuid);

        if (serv != null) {
            BluetoothGattCharacteristic charac = serv.getCharacteristic(dataUuid);

            mUdooBluService.readCharacteristic(address, charac);
            mIReaderListenerMap.put(address + charac.getUuid().toString(), readerListener);
        } else {
            if (readerListener != null)
                readerListener.onError(new UdooBluException(UdooBluException.BLU_SENSOR_NOT_FOUND));
        }

    } else {
        if (BuildConfig.DEBUG)
            Log.i(TAG, "BluManager not ready");

        if (readerListener != null)
            readerListener.onError(new UdooBluException(UdooBluException.BLU_SERVICE_NOT_READY));
    }
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:26,代码来源:UdooBluManager.java

示例5: ensureServiceChangedEnabled

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
/**
 * When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic.
 * In case one of the requirements is not fulfilled this method returns <code>false</code>.
 *
 * @param gatt the gatt device with services discovered
 * @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have
 * the Service Changed characteristic or this characteristic does not have the CCCD.
 */
private boolean ensureServiceChangedEnabled(final BluetoothGatt gatt) {
	if (gatt == null)
		return false;

	// The Service Changed indications have sense only on bonded devices
	final BluetoothDevice device = gatt.getDevice();
	if (device.getBondState() != BluetoothDevice.BOND_BONDED)
		return false;

	final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE);
	if (gaService == null)
		return false;

	final BluetoothGattCharacteristic scCharacteristic = gaService.getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC);
	if (scCharacteristic == null)
		return false;

	return enableIndications(scCharacteristic);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:28,代码来源:BleManager.java

示例6: setCharacteristicValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public void setCharacteristicValue(BluetoothGattService gattService, BluetoothGatt gatt, String k, int v) {
    DeviceCharacteristic dc = getDeviceCharacteristicByKey(k);
    if (dc != null) {
        BluetoothGattCharacteristic lc = null;
        lc = gattService.getCharacteristic(UUID.fromString(dc.uuid.get()));
        if (lc != null) {
            ByteBuffer var2 = ByteBuffer.allocate(2);
            var2.putShort((short) v);
            lc.setValue(var2.array());
            lc.setWriteType(2);
            gatt.writeCharacteristic(lc);
            EventBus.getDefault().post(new DeviceStatusEvent("SET " + k + " TO " + v));
        }
    }
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:16,代码来源:OWDevice.java

示例7: getCharacteristicValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public byte[] getCharacteristicValue(UUID serviceUuid, UUID characteristicUuid){
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic ch = service.getCharacteristic(characteristicUuid);
	if(ch == null)
		return null;
	return ch.getValue();
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:10,代码来源:BLEClient.java

示例8: findWritableCharacteristic

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private BluetoothGattCharacteristic findWritableCharacteristic(BluetoothGattService service, UUID characteristicUUID, int writeType) {
	try {
		BluetoothGattCharacteristic characteristic = null;

		// get write property
		int writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE;
		if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) {
			writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE;
		}

		List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
		for (BluetoothGattCharacteristic c : characteristics) {
			if ((c.getProperties() & writeProperty) != 0 && characteristicUUID.equals(c.getUuid())) {
				characteristic = c;
				break;
			}
		}

		// As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties
		if (characteristic == null) {
			characteristic = service.getCharacteristic(characteristicUUID);
		}

		return characteristic;
	}catch (Exception e) {
		Log.e(LOG_TAG, "Error on findWritableCharacteristic", e);
		return null;
	}
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:30,代码来源:Peripheral.java

示例9: actionGattServicesDiscovered

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
@Override
public void actionGattServicesDiscovered(Device deviceName) {
	if (bleService.getInternalBleService() == null)
		return;
	connectedDevice = deviceName;
	if (!deviceName.isGBA400() && !connectedDevice.isSTB1000())
		return;
	List<BluetoothGattService> services = bleService.getInternalBleService().getSupportedGattServices();
	for (BluetoothGattService service : services) {
		if (service.getUuid().equals(WATCH_FEATURES_SERVICE_UUID)) {
			BluetoothGattCharacteristic characteristic = service.getCharacteristic(FUNCTION_SWITCH_CHARACTERISTIC);
			if (characteristic != null) {
				BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CCC_DESCRIPTOR_UUID);
				descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
				bleService.getInternalBleService().writeDescriptor(descriptor);
				gattCharacteristic = characteristic;
				gattCharacteristic.setValue(READY_MESSAGE.getBytes());
				gattCharacteristic.setWriteType(2);
				bleService.getInternalBleService().writeCharacteristic(gattCharacteristic);
				clientAvailable = true;
				Log.i(TAG, "WatchCtrlService - Discovered!" + characteristic.getUuid().toString());
				reloadPhoneControlModes();
				break;
			}
		}
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:28,代码来源:WatchCtrlService.java

示例10: getDescriptorValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的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

示例11: setCharacteristicValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public boolean setCharacteristicValue(UUID serviceUuid, UUID characteristicUuid, byte[] value, boolean notify){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return false;
	BluetoothGattCharacteristic ch = service.getCharacteristic(characteristicUuid);
	if(ch == null)
		return false;
	boolean rtn = ch.setValue(value);
	if(rtn && notify){
		notifyDevices(ch);
	}
	return rtn;
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:14,代码来源:BLEServer.java

示例12: getCharacteristicValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public byte[] getCharacteristicValue(UUID serviceUuid, UUID characteristicUuid){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return null;
	BluetoothGattCharacteristic ch = service.getCharacteristic(characteristicUuid);
	if(ch == null)
		return null;
	return ch.getValue();
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:10,代码来源:BLEServer.java

示例13: getCharacteristicValueInt

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public int getCharacteristicValueInt(UUID serviceUuid, UUID characteristicUuid, int format, int ofst){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return -1;
	BluetoothGattCharacteristic ch = service.getCharacteristic(characteristicUuid);
	if(ch == null)
		return -1;
	return ch.getIntValue(format, ofst);
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:10,代码来源:BLEServer.java

示例14: setCharacteristicValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public boolean setCharacteristicValue(UUID serviceUuid, UUID characteristicUuid, String value){
	if(gattConnection == null)
		return false;
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return false;
	BluetoothGattCharacteristic ch = service.getCharacteristic(characteristicUuid);
	if(ch == null)
		return false;
	ch.setValue(value);
	return gattConnection.writeCharacteristic(ch);
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEClient.java

示例15: setDescriptorValue

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public boolean setDescriptorValue(UUID serviceUuid, UUID characteristicUuid, UUID descriptorUuid, byte[] value){
	BluetoothGattService service = gattServer.getService(serviceUuid);
	if(service == null)
		return false;
	BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUuid);
	if(characteristic == null)
		return false;
	BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descriptorUuid);
	if(descriptor == null)
		return false;
	return descriptor.setValue(value);
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:13,代码来源:BLEServer.java


注:本文中的android.bluetooth.BluetoothGattService.getCharacteristic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。