本文整理汇总了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);
}
}
}
示例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;
}
}
}
}
示例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);
}
示例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));
}
}
示例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);
}
示例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));
}
}
}
示例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();
}
示例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;
}
}
示例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;
}
}
}
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}