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


Java BluetoothGattService类代码示例

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


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

示例1: onServicesDiscovered

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

示例4: getNotifications

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
public void getNotifications(UUID service, UUID Characteristics) {
    if (!isConnectedToGatt || myGatBand == null) {
        Log.d(TAG, "Cant get notifications from BLE, not initialized.");
        return;
    }

    Log.d(TAG, "* Getting gatt service, UUID:" + service.toString());
    BluetoothGattService myGatService =
            myGatBand.getService(service/*Consts.UUID_SERVICE_MIBAND_SERVICE*/);
    if (myGatService != null) {
        Log.d(TAG, "* Getting gatt Characteristic. UUID: " + Characteristics.toString());

        BluetoothGattCharacteristic myGatChar
                = myGatService.getCharacteristic(Characteristics/*Consts.UUID_BUTTON_TOUCH*/);
        if (myGatChar != null) {
            Log.d(TAG, "* Statring listening");

            // second parametes is for starting\stopping the listener.
            boolean status =  myGatBand.setCharacteristicNotification(myGatChar, true);
            Log.d(TAG, "* Set notification status :" + status);
        }
    }
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:24,代码来源:BLEMiBand2Helper.java

示例5: getGattCharacteristics

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
/**
 * Search for the desired GATT characteristics inside the provided list of GATT services.
 *
 * @param gattServices a {@code List<BluetoothGattService>} to search for the characteristics
 *                     within
 */
private void getGattCharacteristics(List<BluetoothGattService> gattServices) {
	if (gattServices == null) return;

	for (BluetoothGattService gattService : gattServices) {
		if(gattService.getCharacteristic(DRIVE_UUID_CURIE) != null) {
			driveCharacteristic = gattService.getCharacteristic(DRIVE_UUID_CURIE);
		} else if(gattService.getCharacteristic(DRIVE_UUID_HC08) != null) {
			driveCharacteristic = gattService.getCharacteristic(DRIVE_UUID_HC08);
		}

		if(gattService.getCharacteristic(HEADING_UUID_CURIE) != null) {
			headingCharacteristic = gattService.getCharacteristic(HEADING_UUID_CURIE);
			bluetoothLeService.setCharacteristicNotification(headingCharacteristic, true);
		}
	}

	if (driveCharacteristic == null) {
		Toast.makeText(context, "Incompatible Device", Toast.LENGTH_LONG).show();
		connectionEventListener.onBluetoothConnectionEvent(BluetoothLeService.ACTION_ERROR);
	}
}
 
开发者ID:Make-A-Pede,项目名称:Make-A-Pede-Android-App,代码行数:28,代码来源:BluetoothLeConnection.java

示例6: registerMicroBitEvents

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
/**
 * Enables or disables micro:bit event by given event and enable/disable flag.
 *
 * @param eventService Bluetooth GATT service to be registered.
 * @param enable       Enable or disable.
 * @return True, if successful.
 */
private boolean registerMicroBitEvents(BluetoothGattService eventService, boolean enable) {
    // Read (or register for notify) on (1) to receive events generated by the micro:bit.
    BluetoothGattCharacteristic microbit_requirements = eventService.getCharacteristic(CharacteristicUUIDs
            .ES_MICROBIT_EVENT);
    if(microbit_requirements == null) {
        logi("register_eventsFromMicrobit() :: ES_MICROBIT_EVENT Not found");
        return false;
    }
    BluetoothGattDescriptor microbit_requirementsDescriptor = microbit_requirements.getDescriptor(UUIDs
            .CLIENT_DESCRIPTOR);
    if(microbit_requirementsDescriptor == null) {
        logi("register_eventsFromMicrobit() :: CLIENT_DESCRIPTOR Not found");
        return false;
    }

    enableCharacteristicNotification(microbit_requirements, microbit_requirementsDescriptor, enable);
    return true;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:26,代码来源:BLEService.java

示例7: writeData

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
public void writeData(UUID service, UUID Characteristics,byte[] data) {
    if (!isConnectedToGatt || myGatBand == null) {
        Log.d(TAG, "Cant read from BLE, not initialized.");
        return;
    }

    Log.d(TAG, "* Getting gatt service, UUID:" + service.toString());
    BluetoothGattService myGatService =
            myGatBand.getService(service /*Consts.UUID_SERVICE_HEARTBEAT*/);
    if (myGatService != null) {
        Log.d(TAG, "* Getting gatt Characteristic. UUID: " + Characteristics.toString());

        BluetoothGattCharacteristic myGatChar
                = myGatService.getCharacteristic(Characteristics /*Consts.UUID_START_HEARTRATE_CONTROL_POINT*/);
        if (myGatChar != null) {
            Log.d(TAG, "* Writing trigger");
            myGatChar.setValue(data /*Consts.BYTE_NEW_HEART_RATE_SCAN*/);

            boolean status =  myGatBand.writeCharacteristic(myGatChar);
            Log.d(TAG, "* Writting trigger status :" + status);
        }
    }
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:24,代码来源:BLEMiBand2Helper.java

示例8: writeLed

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
private void writeLed(String address, int color, byte func) {
    BluetoothGattService serv = null;
    BluetoothGattCharacteristic charac = null;
    serv = mUdooBluService.getService(address, UDOOBLE.UUID_LED_SERV);
    if (serv != null) {
        switch (color) {
            case Constant.GREEN_LED:
                charac = serv.getCharacteristic(UDOOBLE.UUID_LED_GREEN);
                break;
            case Constant.YELLOW_LED:
                charac = serv.getCharacteristic(UDOOBLE.UUID_LED_YELLOW);
                break;
            case Constant.RED_LED:
                charac = serv.getCharacteristic(UDOOBLE.UUID_LED_RED);
                break;
        }

        byte[] msg = new byte[2];
        msg[0] = func;
        msg[1] = (byte) 0x03;

        mUdooBluService.writeCharacteristic(address, charac, msg);
    }
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:25,代码来源:UdooBluManager.java

示例9: read

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
public void read(UUID serviceUUID, UUID characteristicUUID, Callback callback) {

		if (gatt == null) {
			callback.invoke("BluetoothGatt is null", null);
			return;
		}

		BluetoothGattService service = gatt.getService(serviceUUID);
		BluetoothGattCharacteristic characteristic = findReadableCharacteristic(service, characteristicUUID);

		if (characteristic == null) {
			callback.invoke("Characteristic " + characteristicUUID + " not found.", null);
		} else {
			readCallback = callback;
			if (!gatt.readCharacteristic(characteristic)) {
				readCallback = null;
				callback.invoke("Read failed", null);
			}
		}
	}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:21,代码来源:Peripheral.java

示例10: setUpBatteryService

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
/**
 * Setup Battery Service
 *
 * @return the service
 */
private static BluetoothGattService setUpBatteryService() {
    final BluetoothGattService service = new BluetoothGattService(SERVICE_BATTERY, BluetoothGattService.SERVICE_TYPE_PRIMARY);

    // Battery Level
    final BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(
            CHARACTERISTIC_BATTERY_LEVEL,
            BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ,
            BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED);

    final BluetoothGattDescriptor clientCharacteristicConfigurationDescriptor = new BluetoothGattDescriptor(
            DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,
            BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE);
    clientCharacteristicConfigurationDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    characteristic.addDescriptor(clientCharacteristicConfigurationDescriptor);

    while (!service.addCharacteristic(characteristic));

    return service;
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:25,代码来源:HidPeripheral.java

示例11: detectSensors

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
private void detectSensors(String address, IReaderListener<byte[]> readerListener) {
    if (isBluManagerReady) {
        UUID servUuid = UDOOBLE.UUID_SENSORS_SERV;
        UUID dataUuid = UDOOBLE.UUID_SENSOR_DATA;

        BluetoothGattService serv = mUdooBluService.getService(address, servUuid);

        if (serv != null) {
            BluetoothGattCharacteristic charac = serv.getCharacteristic(dataUuid);

            mUdooBluService.readCharacteristic(address, charac);
            mIReaderListenerMap.put(address + charac.getUuid().toString(), readerListener);
        } else {
            if (readerListener != null)
                readerListener.onError(new UdooBluException(UdooBluException.BLU_SENSOR_NOT_FOUND));
        }

    } else {
        if (BuildConfig.DEBUG)
            Log.i(TAG, "BluManager not ready");

        if (readerListener != null)
            readerListener.onError(new UdooBluException(UdooBluException.BLU_SERVICE_NOT_READY));
    }
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:26,代码来源:UdooBluManager.java

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

示例13: writeCharacteristic

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
private void writeCharacteristic(String serviceGuid, String characteristic, int value, int type) {
    if(!isConnected()) {
        logi("writeCharacteristic() :: Not connected. Returning");
        return;
    }

    BluetoothGattService s = getService(UUID.fromString(serviceGuid));
    if(s == null) {
        logi("writeCharacteristic() :: Service not found");
        return;
    }

    BluetoothGattCharacteristic c = s.getCharacteristic(UUID.fromString(characteristic));
    if(c == null) {
        logi("writeCharacteristic() :: characteristic not found");
        return;
    }

    c.setValue(value, type, 0);
    int ret = writeCharacteristic(c);
    logi("writeCharacteristic() :: returns - " + ret);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:23,代码来源:BLEService.java

示例14: readFirmwareVersion

import android.bluetooth.BluetoothGattService; //导入依赖的package包/类
public void readFirmwareVersion(final String address, final IReaderListener<byte[]> readerListener) {
    addOperation(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            if (isBluManagerReady) {
                UUID servUuid = TIUUID.UUID_DEVINFO_SERV;
                UUID dataUuid = TIUUID.UUID_DEVINFO_FWREV;
                BluetoothGattService serv = mUdooBluService.getService(address, servUuid);

                if (serv != null) {
                    BluetoothGattCharacteristic charac = serv.getCharacteristic(dataUuid);
                    mUdooBluService.readCharacteristic(address, charac);
                    mIReaderListenerMap.put(address + charac.getUuid().toString(), readerListener);
                } else {
                    if (readerListener != null)
                        readerListener.onError(new UdooBluException(UdooBluException.BLU_GATT_SERVICE_NOT_FOUND));
                }
            }
            return null;
        }
    });
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:23,代码来源:UdooBluManager.java

示例15: isRequiredServiceSupported

import android.bluetooth.BluetoothGattService; //导入依赖的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);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:24,代码来源:UARTManager.java


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