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


Java BluetoothGattService.getCharacteristics方法代码示例

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


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

示例1: discoverServices

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private synchronized void discoverServices() throws InterruptedException {
    if (VDBG) { Log.d(TAG, "discoverServices: [CMD]"); }
    while (lastMessage != MESSAGE_SERVICES_DISCOVERED) {
        mBtGatt.discoverServices();
        wait(1000);
    }
    if (VDBG) {
        Log.d(TAG, "discoverServices: [DONE] ");
        for (BluetoothGattService s : mBtGatt.getServices()) {
            Log.d(TAG, "discoverServices: found " + s.getUuid());
            for (BluetoothGattCharacteristic c : s.getCharacteristics()) {
                Log.d(TAG, "--> characteristic: " + c.getUuid() + ":" + String.format("%x", c.getInstanceId()));
            }
        }
    }
    lastMessage = -1;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:18,代码来源:GattClient.java

示例2: findReadableCharacteristic

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private BluetoothGattCharacteristic findReadableCharacteristic(BluetoothGattService service, UUID characteristicUUID) {
	BluetoothGattCharacteristic characteristic = null;

	int read = BluetoothGattCharacteristic.PROPERTY_READ;

	List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
	for (BluetoothGattCharacteristic c : characteristics) {
		if ((c.getProperties() & read) != 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;
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:21,代码来源:Peripheral.java

示例3: getSupportedGattServices

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
public List<BluetoothGattService> getSupportedGattServices() {
    if (mBluetoothGatt == null) {
        return null;
    }

    List<BluetoothGattService> gattServices = mBluetoothGatt.getServices();

    for (BluetoothGattService gattService : gattServices) {
        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            String uuid = gattCharacteristic.getUuid().toString();
            if(uuid.equalsIgnoreCase(UUID_NOTIFY.toString())){
                mNotifyCharacteristic = gattCharacteristic;
                mBluetoothGatt.setCharacteristicNotification(gattCharacteristic, true);
                ULog.i("setCharacteristicNotification : " + uuid);
                BluetoothGattDescriptor descriptor = gattCharacteristic
                        .getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                mBluetoothGatt.writeDescriptor(descriptor);
            }
        }
    }
    return gattServices;
}
 
开发者ID:WillFlower,项目名称:BluetoothCtrl,代码行数:25,代码来源:BluetoothLeService.java

示例4: onServicesDiscovered

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

示例5: actionGattServicesDiscovered

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
@Override
public void actionGattServicesDiscovered(Device device) {
	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) {
		for (BluetoothGattCharacteristic gattCharacteristic : service.getCharacteristics()) {
			if (gattCharacteristic.getUuid().equals(CURRENT_TIME_CHARACTERISTIC_UUID)) {
				Log.i(TAG, "TimeService - Discovered!" + gattCharacteristic.getUuid().toString());
				timeGattCharacteristic = gattCharacteristic;
			}
		}
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:17,代码来源:TimeService.java

示例6: actionGattServicesDiscovered

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
@Override
public void actionGattServicesDiscovered(Device device) {
	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) {
		for (BluetoothGattCharacteristic gattCharacteristic : service.getCharacteristics()) {
			if (gattCharacteristic.getUuid().equals(ALERT_CHARACTERISTIC_UUID)) {
				Log.i(TAG, "AlertService - Discovered!" + gattCharacteristic.getUuid().toString());
				alertGattCharacteristic = gattCharacteristic;
			}
		}
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:17,代码来源:DefaultAlertService.java

示例7: 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

示例8: updateServices

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private void updateServices(Connection conn) {
    items.clear();
    for (BluetoothGattService service : conn.getServices()) {
        items.add(service);
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            items.add(characteristic);
        }
    }
    notifyDataSetChanged();
}
 
开发者ID:inovait,项目名称:neatle,代码行数:11,代码来源:DeviceDetails.java

示例9: start

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

示例10: actionGattServicesDiscovered

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
@Override
public void actionGattServicesDiscovered(Device device) {
	List<BluetoothGattService> services = bleService.getInternalBleService().getSupportedGattServices();
	for (BluetoothGattService service : services) {
		for (BluetoothGattCharacteristic gattCharacteristic : service.getCharacteristics()) {
			Log.i(TAG, "LogClientService - Discovered. Service: " + service.getUuid().toString() + " - Characteristic: " + gattCharacteristic.getUuid().toString());
		}
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:10,代码来源:LogClientService.java

示例11: printServices

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

示例12: getGattServices

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
/**
 * get Gatt services and save as arrayList
 * @param gattServices
 */
private ArrayList<ArrayList<BluetoothGattCharacteristic>> getGattServices(List<BluetoothGattService> gattServices) {
    // check Gatt service
    if (gattServices == null) return null;

    ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<>();
    ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<>();
    mGattCharacteristics = new ArrayList<>();

    // loops through available GATT services
    for (BluetoothGattService gattService : gattServices) {
        HashMap<String, String> currentServiceData = new HashMap<>();
        String uuid = gattService.getUuid().toString();
        currentServiceData.put("LIST_NAME", BluetoothGattAttributes.lookup(uuid, getString(R.string.unknown_service)));
        currentServiceData.put("LIST_UUID", uuid);
        gattServiceData.add(currentServiceData);
        ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<>();
        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<>();

        // loops through available characteristics
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            charas.add(gattCharacteristic);
            HashMap<String, String> currentCharaData = new HashMap<>();
            uuid = gattCharacteristic.getUuid().toString();
            currentCharaData.put("LIST_NAME", BluetoothGattAttributes.lookup(uuid, getString(R.string.unknown_characteristic)));
            currentCharaData.put("LIST_UUID", uuid);
            gattCharacteristicGroupData.add(currentCharaData);
            Log.e(TAG, "LIST_NAME : " + BluetoothGattAttributes.lookup(uuid, getString(R.string.unknown_characteristic)) + ", LIST_UUID : " + uuid);
        }

        mGattCharacteristics.add(charas);
        gattCharacteristicData.add(gattCharacteristicGroupData);
    }
    return mGattCharacteristics;
}
 
开发者ID:skydoves,项目名称:MagicLight-Controller,代码行数:40,代码来源:BluetoothLeService.java

示例13: checkServices

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private void checkServices(List<BluetoothGattService> gattServices) {
        if (gattServices == null) return;
        String uuid = null;
        String unknownServiceString = getResources().getString(R.string.unknown_service);
        String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
        ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
        ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData
                = new ArrayList<ArrayList<HashMap<String, String>>>();
        mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

        // Loops through available GATT Services.
        for (BluetoothGattService gattService : gattServices) {
            HashMap<String, String> currentServiceData = new HashMap<String, String>();
            //           uuid = gattService.getUuid().toString();
            UUID serviceUuid = gattService.getUuid();
            if (hackmelockDevice.HACKMELOCK_SERVICE_UUID.equals(serviceUuid)) {
                Log.d("GattServices", "Found Hackmelock service!");
                hackmelockService = gattService;
                hackmelockCommandChar = hackmelockService.getCharacteristic(hackmelockDevice.HACKMELOCK_COMMAND_UUID);
                hackmelockStatusChar = hackmelockService.getCharacteristic(hackmelockDevice.HACKMELOCK_STATUS_UUID);
                hackmelockDataTransferChar = hackmelockService.getCharacteristic(hackmelockDevice.HACKMELOCK_DATATRANSFER_UUID);

                ArrayList<HashMap<String, String>> gattCharacteristicGroupData =
                        new ArrayList<HashMap<String, String>>();
                List<BluetoothGattCharacteristic> gattCharacteristics =
                        gattService.getCharacteristics();
                ArrayList<BluetoothGattCharacteristic> charas =
                        new ArrayList<BluetoothGattCharacteristic>();

                // Loops through available Characteristics.
                for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                    charas.add(gattCharacteristic);
                    HashMap<String, String> currentCharaData = new HashMap<String, String>();
//                    uuid = gattCharacteristic.getUuid().toString();
                    UUID characteristicUuid = gattCharacteristic.getUuid();
                    if (hackmelockDevice.HACKMELOCK_STATUS_UUID.equals(characteristicUuid)) {
                        Log.d("GattServices", "Found Hackmelock status characteristic");
                        //if device already paired, read status = auth challenge
                        if (hackmelockDevice.status == HackmelockDevice.Status.PAIRED) {
//                            hackmelockDevice.status = HackmelockDevice.Status.AUTHENTICATING;
                            authenticate();
                        } else {
                            Log.d("GattServices","Status: " + hackmelockDevice.status.toString());
                            // else - if device not yet paired, read status = init pairing
                            mBluetoothLeService.readCharacteristic(gattCharacteristic);
                        }
                    }
                }
                mGattCharacteristics.add(charas);
                gattCharacteristicData.add(gattCharacteristicGroupData);

            }
        }
    }
 
开发者ID:smartlockpicking,项目名称:hackmelock-android,代码行数:55,代码来源:DeviceControlActivity.java

示例14: asWritableMap

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

示例15: initService

import android.bluetooth.BluetoothGattService; //导入方法依赖的package包/类
private void initService() {
    List<BluetoothGattService> list = btGatt.getServices();
    BluetoothGattService service = null;
    for (BluetoothGattService s : list) {
        if (s.getUuid().toString().substring(4, 8).equalsIgnoreCase(serviceId)) {
            service = s;
            break;
        }
    }

    if (service == null) {
        onError(ErrorCode.IO);
        taskConnectTimeout.cancel();
        return;
    }

    BluetoothGattCharacteristic characteristic = null;
    List<BluetoothGattCharacteristic> chars = service.getCharacteristics();
    for (BluetoothGattCharacteristic c : chars) {
        int props = c.getProperties();
        int desiredProps = BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_NOTIFY;
        if ((props & desiredProps) == desiredProps) {
            characteristic = c;
            break;
        }
    }

    if (characteristic == null) {
        onError(ErrorCode.IO);
        taskConnectTimeout.cancel();
        return;
    }
    charSerial = characteristic;

    BluetoothGattDescriptor clientConfig = null;
    List<BluetoothGattDescriptor> descs = charSerial.getDescriptors();
    for (BluetoothGattDescriptor d : descs) {
        if (d.getUuid().toString().substring(4, 8).equalsIgnoreCase("2902")) {
            clientConfig = d;
            break;
        }
    }

    if (clientConfig == null) {
        onError(ErrorCode.IO);
        taskConnectTimeout.cancel();
        return;
    }

    btGatt.setCharacteristicNotification(charSerial, true);

    clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    btGatt.writeDescriptor(clientConfig);
}
 
开发者ID:e-regular-games,项目名称:arduator,代码行数:55,代码来源:ArduinoCommBle.java


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