當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGattCharacteristic.FORMAT_SINT16屬性代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.FORMAT_SINT16屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.FORMAT_SINT16屬性的具體用法?Java BluetoothGattCharacteristic.FORMAT_SINT16怎麽用?Java BluetoothGattCharacteristic.FORMAT_SINT16使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.bluetooth.BluetoothGattCharacteristic的用法示例。


在下文中一共展示了BluetoothGattCharacteristic.FORMAT_SINT16屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: broadcastUpdate

private void broadcastUpdate(final String action,
                             final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // This is special handling for the Environmental Sensing profile.  Data parsing is
    // carried out as per profile specifications:
    // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml
    if (IGrowGattAttributes.TEMPERATURE.equals(characteristic.getUuid())) {

        int format = BluetoothGattCharacteristic.FORMAT_SINT16;
        Log.d(TAG, "Temperature format SINT16.");

        final int temperature = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received temperature: %d", temperature));
        intent.putExtra(BluetoothLeService.EXTRA_DATA, String.valueOf(temperature));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for (byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(BluetoothLeService.EXTRA_DATA, new String(data)
                    + "\n" + stringBuilder.toString());
        }
    }
    sendBroadcast(intent);
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:28,代碼來源:BluetoothLeScanService.java

示例2: broadcastUpdate

private void broadcastUpdate(final String action,
                             final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // This is special handling for the Environmental Sensing profile.  Data parsing is
    // carried out as per profile specifications:
    // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml
    if (IGrowGattAttributes.TEMPERATURE.equals(characteristic.getUuid())) {

        int format = BluetoothGattCharacteristic.FORMAT_SINT16;
        Log.d(TAG, "Temperature format SINT16.");

        final int temperature = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received temperature: %d", temperature));
        intent.putExtra(EXTRA_DATA, String.valueOf(temperature));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for(byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
        }
    }
    sendBroadcast(intent);
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:27,代碼來源:BluetoothLeService.java


注:本文中的android.bluetooth.BluetoothGattCharacteristic.FORMAT_SINT16屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。