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


Java BluetoothGatt.getServices方法代码示例

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


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

示例1: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        for(BluetoothGattService service : gatt.getServices()){
            Log.d(mTAG, "service: " + service.getUuid().toString());
        }
        //Log.d(mTAG, "mGattMiFloraService: " + UUID_MI_FLORA_SERVICE_ID.toString());
        mGattMiFloraService = gatt.getService(UUID_MI_FLORA_SERVICE_ID);
        if(mGattMiFloraService != null){
            boolean rs = gatt.readCharacteristic(mGattMiFloraService.getCharacteristic(UUID_MI_FLORA_FIRMWARE));
            if(!rs){
                Log.i(mTAG, "Can't read mGattMiFloraFwCharacteristic");
            }
        }
    }
    else{
        gatt.close();
        mIsConnecting = false;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:21,代码来源:MiFloraSensorEntity.java

示例2: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
  for (BluetoothGattService service : gatt.getServices()) {
    if (IMMEDIATE_ALERT_SERVICE.equals(service.getUuid())) {
      BlePair pair = bluetoothGatt.get(gatt.getDevice().getAddress());
      if (pair != null) {
        pair.alertCharacteristic = getCharacteristic(
            gatt,
            IMMEDIATE_ALERT_SERVICE,
            ALERT_LEVEL_CHARACTERISTIC
        );
        gatt.readCharacteristic(pair.alertCharacteristic);
      }
    }

    if (FIND_ME_SERVICE.equals(service.getUuid())) {
      if (!service.getCharacteristics().isEmpty()) {
        buttonCharacteristic = service.getCharacteristics().get(0);
        setCharacteristicNotification(gatt, buttonCharacteristic, true);
      }
    }
  }
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:24,代码来源:BleService.java

示例3: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Callback invoked when the list of remote services, characteristics and descriptors for the remote device have been updated, ie new services have been discovered.
 *
 * @param gatt 返回的是本次连接的gatt对象
 * @param status
 */
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    Log.d(Tag, "onServicesDiscovered status" + status);
    mServiceList = gatt.getServices();
    if (mServiceList != null) {
        System.out.println(mServiceList);
        System.out.println("Services num:" + mServiceList.size());
    }

    for (BluetoothGattService service : mServiceList){
        List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
        System.out.println("扫描到Service:" + service.getUuid());

        for (BluetoothGattCharacteristic characteristic : characteristics) {
            System.out.println("characteristic: " + characteristic.getUuid() );
        }
    }
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:25,代码来源:BleActivity.java

示例4: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
// New services discovered
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    resetConnectionTimeoutChecker();

    if (status == BluetoothGatt.GATT_SUCCESS) {
        Log.w("BLE", "onServicesDiscovered " + gatt.getService(Globals.SNACH_SYSTEM_SERVICE_UUID));

        for(BluetoothGattService se : gatt.getServices()){
            Log.i("BLE", "discovered Service: "+se.getUuid()+"   "+se.getCharacteristics().toString());
        }
    } else {
        Log.w("BLE", "onServicesDiscovered received: " + status);
    }
    setNotifySensor(gatt);
    didInitialTransfer = false;
}
 
开发者ID:ordsen,项目名称:Snach-Android,代码行数:18,代码来源:BLEManager.java

示例5: start

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
protected void start(Connection connection, BluetoothGatt gatt) {
    List<BluetoothGattService> services = gatt.getServices();
    for (BluetoothGattService service : services) {
        List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
        for (BluetoothGattCharacteristic characteristic : characteristics) {
            int props = characteristic.getProperties();
            if ((props & BluetoothGattCharacteristic.PROPERTY_READ) != 0) {
                queue.add(characteristic);
            }
        }
    }

    readNext(gatt);
}
 
开发者ID:inovait,项目名称:neatle,代码行数:16,代码来源:ReadAllCommand.java

示例6: printServices

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * 打印所有的service, 特征吗, 描述符
 * 在service被发现后, 可以调用
 * @param gatt
 */
public static void printServices(BluetoothGatt gatt) {
    if (gatt != null) {
        for (BluetoothGattService service : gatt.getServices()) {
            BleLog.i(TAG, "service: " + service.getUuid());
            for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
                BleLog.d(TAG, "  characteristic: " + characteristic.getUuid() + " value: " + Arrays.toString(characteristic.getValue()));
                for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
                    BleLog.v(TAG, "        descriptor: " + descriptor.getUuid() + " value: " + Arrays.toString(descriptor.getValue()));
                }
            }
        }
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:19,代码来源:BluetoothUtil.java

示例7: getSupportedGattServices

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Retrieves a list of supported GATT services on the connected device with @address.
 * This should be invoked only after {@code BluetoothGatt#discoverServices()} completes
 * successfully.
 *
 * @return A {@code List} of supported services.
 */
public List<BluetoothGattService> getSupportedGattServices(String mac) {
    List<BluetoothGattService> list = new ArrayList<>();

    if (mBluetoothGatts.containsKey(mac)) {
        BluetoothGatt bluetoothGatt = mBluetoothGatts.get(mac);
        if (bluetoothGatt != null)
            list = bluetoothGatt.getServices();
    }

    return list;
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:19,代码来源:UdooBluService.java

示例8: asWritableMap

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


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