本文整理匯總了Java中android.bluetooth.BluetoothGatt.getService方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGatt.getService方法的具體用法?Java BluetoothGatt.getService怎麽用?Java BluetoothGatt.getService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGatt
的用法示例。
在下文中一共展示了BluetoothGatt.getService方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onServicesDiscovered
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
// CHECK 이 부분이 언제언제 불리는지 확인할 필요가 있다 잘못하면 매번 생성하는수가 있다.
// 따라서 필수 체크
if ( status == BluetoothGatt.GATT_SUCCESS ) {
BluetoothGattService service = gatt.getService(ServiceUuidV2);
if ( service != null )
{
mProtocolVer = 2;
mConnectionThread = new ConnectedThread(mProtocolVer);
mConnectionThread.start();
initCharacteristic(mProtocolVer);
}
else {
NLog.d("cannot find service");
disconnect();
}
}
}
示例2: obtenerCaracteristicasDescriptoresAccelGyroCC2650
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
private boolean obtenerCaracteristicasDescriptoresAccelGyroCC2650(BluetoothGatt gatt){
boolean todoCorrecto = false;
BluetoothGattService acelerometroService = gatt.getService(UUID_MOVEMENT_SERVICE);
if(acelerometroService != null){
this.movementCharacteristic = acelerometroService.getCharacteristic(UUID_MOVEMENT_DATA);
this.movementConf = acelerometroService.getCharacteristic(UUID_MOVEMENT_CONF);
this.movementPeriod = acelerometroService.getCharacteristic(UUID_MOVEMENT_PERIOD);
if(movementCharacteristic != null && movementConf != null){
this.config = movementCharacteristic.getDescriptor(UUID_CCC);
todoCorrecto = true;
}
}
return todoCorrecto;
}
示例3: 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);
}
}
示例4: initGatt
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
protected Queue<BleManager.Request> initGatt(final BluetoothGatt gatt) {
final BluetoothGattService service = gatt.getService(UART_SERVICE_UUID);
mTXCharacteristic = service.getCharacteristic(UART_TX_CHARACTERISTIC_UUID);
mRXCharacteristic = service.getCharacteristic(UART_RX_CHARACTERISTIC_UUID);
final int rxProperties = mRXCharacteristic.getProperties();
boolean writeRequest = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0;
// Set the WRITE REQUEST type when the characteristic supports it. This will allow to send long write (also if the characteristic support it).
// In case there is no WRITE REQUEST property, this manager will divide texts longer then 20 bytes into up to 20 bytes chunks.
if (writeRequest)
mRXCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
// We don't want to enable notifications on TX characteristic as we are not showing them here. A watch may be just used to send data. At least now.
// final LinkedList<BleManager.Request> requests = new LinkedList<>();
// requests.push(BleManager.Request.newEnableNotificationsRequest(mTXCharacteristic));
// return requests;
return null;
}
示例5: isRequiredServiceSupported
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public boolean isRequiredServiceSupported(final BluetoothGatt gatt) {
final BluetoothGattService service = gatt.getService(UART_SERVICE_UUID);
if (service != null) {
mRXCharacteristic = service.getCharacteristic(UART_RX_CHARACTERISTIC_UUID);
mTXCharacteristic = service.getCharacteristic(UART_TX_CHARACTERISTIC_UUID);
}
boolean writeRequest = false;
boolean writeCommand = false;
if (mRXCharacteristic != null) {
final int rxProperties = mRXCharacteristic.getProperties();
writeRequest = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0;
writeCommand = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0;
// Set the WRITE REQUEST type when the characteristic supports it. This will allow to send long write (also if the characteristic support it).
// In case there is no WRITE REQUEST property, this manager will divide texts longer then 20 bytes into up to 20 bytes chunks.
if (writeRequest)
mRXCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
}
return mRXCharacteristic != null && mTXCharacteristic != null && (writeRequest || writeCommand);
}
示例6: getService
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
public BluetoothGattService getService(String mBleAddress, UUID uuidLedServ) {
BluetoothGattService gattService = null;
BluetoothGatt bluetoothGatt = checkAndGetGattItem(mBleAddress);
if (bluetoothGatt != null) {
gattService = bluetoothGatt.getService(uuidLedServ);
}
return gattService;
}
示例7: isOptionalServiceSupported
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
protected boolean isOptionalServiceSupported(final BluetoothGatt gatt) {
final BluetoothGattService iaService = gatt.getService(IMMEDIATE_ALERT_SERVICE_UUID);
if (iaService != null) {
mAlertLevelCharacteristic = iaService.getCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID);
}
return mAlertLevelCharacteristic != null;
}
示例8: onDescriptorWrite
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
* Callback indicating the result of a descriptor write operation.
*
* @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
* @param descriptor Descriptor that was writte to the associated
* remote device.
* @param status The result of the write operation
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
*/
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
// boolean indicating whether or not the next step is successful, default is false
boolean success = false;
// Check if writing descriptor was successful and force the action notification if it
// was
if (status == BluetoothGatt.GATT_SUCCESS) {
// Check if the SPIN Service is found
final BluetoothGattService spinService = gatt.getService(SPIN_SERVICE_UUID);
if (spinService != null) {
// Check if the Command Characteristic is found, write the new value and store
// the result
final BluetoothGattCharacteristic commandCharacteristic
= spinService.getCharacteristic(COMMAND_CHARACTERISTIC_UUID);
if (commandCharacteristic != null) {
// Set the value to 0x0801
commandCharacteristic.setValue(
new byte[]{
(byte) 0x08, // commandId = force action notification (8)
(byte) 0x01 // enable = false (0) or true (1)
}
);
success = gatt.writeCharacteristic(commandCharacteristic);
}
}
}
onStep(gatt, success);
}
示例9: getCharacteristic
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
* 根據service, character , 獲取character
* @param gatt
* @param serviceUUID
* @param charactUUID
* @return
*/
public static BluetoothGattCharacteristic getCharacteristic(BluetoothGatt gatt, String serviceUUID, String charactUUID) {
BluetoothGattService service = gatt.getService(UUID.fromString(serviceUUID));
if (service != null) {
return service.getCharacteristic(UUID.fromString(charactUUID));
}
return null;
}
示例10: isRequiredServiceSupported
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
protected boolean isRequiredServiceSupported(final BluetoothGatt gatt) {
BluetoothGattService service = gatt.getService(BP_SERVICE_UUID);
if (service != null) {
mBPMCharacteristic = service.getCharacteristic(BPM_CHARACTERISTIC_UUID);
mICPCharacteristic = service.getCharacteristic(ICP_CHARACTERISTIC_UUID);
}
return mBPMCharacteristic != null;
}
示例11: isRequiredServiceSupported
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public boolean isRequiredServiceSupported(final BluetoothGatt gatt) {
final BluetoothGattService service = gatt.getService(GLS_SERVICE_UUID);
if (service != null) {
mGlucoseMeasurementCharacteristic = service.getCharacteristic(GM_CHARACTERISTIC);
mGlucoseMeasurementContextCharacteristic = service.getCharacteristic(GM_CONTEXT_CHARACTERISTIC);
mRecordAccessControlPointCharacteristic = service.getCharacteristic(RACP_CHARACTERISTIC);
}
return mGlucoseMeasurementCharacteristic != null && mRecordAccessControlPointCharacteristic != null;
}
示例12: isRequiredServiceSupported
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
protected boolean isRequiredServiceSupported(final BluetoothGatt gatt) {
final BluetoothGattService service = gatt.getService(HT_SERVICE_UUID);
if (service != null) {
mHTCharacteristic = service.getCharacteristic(HT_MEASUREMENT_CHARACTERISTIC_UUID);
}
return mHTCharacteristic != null;
}
示例13: getCharacteristic
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
private BluetoothGattCharacteristic getCharacteristic(
@NonNull BluetoothGatt bluetoothgatt,
@NonNull UUID serviceUuid,
@NonNull UUID characteristicUuid
) {
BluetoothGattService service = bluetoothgatt.getService(serviceUuid);
if (service != null)
return service.getCharacteristic(characteristicUuid);
return null;
}
示例14: isRequiredServiceSupported
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public boolean isRequiredServiceSupported(final BluetoothGatt gatt) {
final BluetoothGattService service = gatt.getService(CYCLING_SPEED_AND_CADENCE_SERVICE_UUID);
if (service != null) {
mCSCMeasurementCharacteristic = service.getCharacteristic(CSC_MEASUREMENT_CHARACTERISTIC_UUID);
}
return mCSCMeasurementCharacteristic != null;
}
示例15: 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;
}