當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。