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