本文整理匯總了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;
}
}
示例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);
}
}
}
}
示例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() );
}
}
}
示例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;
}
示例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);
}
示例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()));
}
}
}
}
}
示例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;
}
示例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;
}