Example usage for android.bluetooth BluetoothGattCharacteristic getUuid

List of usage examples for android.bluetooth BluetoothGattCharacteristic getUuid

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGattCharacteristic getUuid.

Prototype

public UUID getUuid() 

Source Link

Document

Returns the UUID of this characteristic

Usage

From source file:com.jordanfitzgibbon.rfduinohrm.RFduinoService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    if (UUID_RECEIVE.equals(characteristic.getUuid())) {
        final Intent intent = new Intent(action);
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
        sendBroadcast(intent, Manifest.permission.BLUETOOTH);
        Log.w(TAG, "BTLE Data received and broadcasted");

        // Create notification
        Intent notificationIntent = new Intent(RFduinoService.this,
                com.jordanfitzgibbon.rfduinohrm.MainActivity.class);
        notificationIntent.setAction("RFduinoTest_CallToMain");
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(RFduinoService.this, 0, notificationIntent, 0);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(RFduinoService.this)
                .setContentTitle("Bluetooth Data").setTicker("New Bluetooth Data Received")
                .setContentText("Data:" + characteristic.getValue() + "\nOr: " + characteristic.getValue())
                //.setContentText("Data:" + HexAsciiHelper.bytesToAsciiMaybe(characteristic.getValue()) + "\nOr: " + HexAsciiHelper.bytesToHex(characteristic.getValue()))
                //.setSmallIcon(R.drawable.ic_launcher)
                //                    .setLargeIcon(
                //                          Bitmap.createScaledBitmap(icon, 128, 128, false))
                .setAutoCancel(true).setContentIntent(pendingIntent);
        mNotificationManager.notify(110, mBuilder.build());
    }/*from   ww w. j  a  v a2s.co  m*/
}

From source file:com.ec.android.module.bluetooth40.BluetoothLeService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);
    ////from   w  w w .  j  a va2 s . c  o m
    if (SampleGattAttributes.NOTIFY_CHARACTERISTIC_CONFIG.equals(characteristic.getUuid().toString())) {
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            intent.putExtra(EXTRA_DATA, data);
        }
    }
    //
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:com.example.android.alertbuddy.BluetoothLeService.java

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

    UUID uuid = characteristic.getUuid();
    final byte[] data = characteristic.getValue();

    if (uuid.equals(RX_UUID)) {
        if (data != null && data.length > 0) {
            intent.putExtra(EXTRA_DATA, data);
        }//from ww  w.j  a  v a  2 s .com
    }
    sendBroadcast(intent);
}

From source file:io.v.android.impl.google.discovery.plugins.ble.Driver.java

public void onGattRead(BluetoothDevice device, BluetoothGattService service) {
    Map<String, byte[]> characteristics;
    ImmutableMap.Builder<String, byte[]> builder = new ImmutableMap.Builder();
    for (BluetoothGattCharacteristic c : service.getCharacteristics()) {
        builder.put(c.getUuid().toString(), c.getValue());
    }//from ww w  .  j a  v a  2  s .c  om
    characteristics = builder.build();

    synchronized (this) {
        if (mScanSeens == null) {
            return;
        }
        Integer rssi = mScanSeens.get(device);
        if (rssi == null) {
            return;
        }
        mScanHandler.onDiscovered(service.getUuid().toString(), characteristics, rssi);
        mOnServiceReadCallbacks++;
    }
}

From source file:com.nordicsemi.UART_UDP_PROXY.UartService.java

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

    if (TX_CHAR_UUID.equals(characteristic.getUuid())) {
        // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {//from   w  w w  .  jav a 2 s  .  c  o m

    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    // DA
    onDataReceived(characteristic.getStringValue(0));
}

From source file:com.example.bluetooth.RFduinoService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    if (UUID_RECEIVE.equals(characteristic.getUuid())) {
        final Intent intent = new Intent(action);
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
        //sendBroadcast(intent, Manifest.permission.BLUETOOTH); // Left it, to avoid modify BluetoothActivty due to time constraints
        mServiceStart = true;/*from   w  w  w  .  j a  v a 2  s .  co m*/
        intent.putExtra(ACTION_DATA_TAG, true);
        sendOrderedBroadcast(intent, Manifest.permission.BLUETOOTH, new BroadcastReceiver() {
            @Override
            public void onReceive(Context pContext, Intent pIntent) {
                //String pResultData = getResultData();
                if (getResultData() != null && getResultData().equals("Tag_Activity")) {
                    mServiceStart = false;
                    Log.wtf(TAG, "StartService false");
                }

                // Trigger Reminder Service
                if (mServiceStart) {
                    final Intent mReminderIntent = new Intent(getApplicationContext(), ReminderService.class);
                    mReminderIntent.putExtra(ACTION_DATA_SERVICE, true);
                    mReminderIntent.putExtra(EXTRA_DATA, characteristic.getValue());
                    getApplicationContext().startService(mReminderIntent);
                }

            }
        }, null, Activity.RESULT_OK, null, null);
        Log.w(TAG, "BTLE Data received and Broadcasted");

        //            // Trigger Reminder Service
        //            if(mServiceStart) {
        //                final Intent mReminderIntent = new Intent(getApplicationContext(), ReminderService.class);
        //                mReminderIntent.putExtra(ACTION_DATA_SERVICE, true);
        //                mReminderIntent.putExtra(EXTRA_DATA, characteristic.getValue());
        //                getApplicationContext().startService(mReminderIntent);
        //            }
    }
}

From source file:com.github.w666.ezonwatch.BluetoothLeService.java

/**
 * Enables or disables notification on a give characteristic.
 *
 * @param characteristic Characteristic to act on.
 * @param enabled If true, enable notification.  False otherwise.
 *///from   ww w.ja va  2s.  c om
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
    if (characteristic.getUuid().equals(UUID_EZON_MAIN)) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        descriptor.setValue(
                enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}

From source file:com.cypress.cysmart.BLEServiceFragments.DeviceInformationService.java

/**
 * Method to get required characteristics from service
 *///from  w  w w.  ja va 2 s . com
void getGattData() {
    List<BluetoothGattCharacteristic> gattCharacteristics = mService.getCharacteristics();
    for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
        String uuidchara = gattCharacteristic.getUuid().toString();
        if (uuidchara.equalsIgnoreCase(GattAttributes.MANUFACTURER_NAME_STRING)) {
            Logger.i("Characteristic div" + uuidchara);
            mReadCharacteristic = gattCharacteristic;
            prepareBroadcastDataRead(gattCharacteristic);
            break;
        }
    }
}

From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java

/**
 * Method to get required characteristics from service
 *///from   w w  w.  j a  v a2  s.co m
void getGattData() {
    List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics();
    for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
        String uuidchara = gattCharacteristic.getUuid().toString();
        if (uuidchara.equalsIgnoreCase(GattAttributes.CSC_MEASUREMENT)) {
            mNotifyCharacteristic = gattCharacteristic;
            prepareBroadcastDataNotify(mNotifyCharacteristic);
        }
    }
}

From source file:com.cqupt.sensor_ble.activity.UartService.java

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

    if (TX_CHAR_UUID.equals(characteristic.getUuid())) {
        final byte[] byte_data = characteristic.getValue();
        if (byte_data != null && byte_data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(byte_data.length);
            for (byte byteChar : byte_data) {
                stringBuilder.append(String.format("%X", byteChar));
            }//from www  .  jav a2s  .c om
            temp.append(stringBuilder.toString()).append(" ");
            if ("A".equals(stringBuilder.toString())) { //?
                String string = temp.toString();
                if (string.length() == 34) { //??
                    String t = String.valueOf(string.charAt(7)) + String.valueOf(string.charAt(10)); //??
                    String h = String.valueOf(string.charAt(25)) + String.valueOf(string.charAt(28));//??
                    int[] int_array = new int[2];
                    int_array[0] = Integer.parseInt(h);
                    int_array[1] = Integer.parseInt(t);
                    intent.putExtra(EXTRA_DATA, int_array);
                }
                temp = null;
                temp = new StringBuilder(38);
            }
        }
    } else if (RX_CHAR_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(CHAR1_DATA,
                "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));

    } else if (Battery_Level_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(EXTRA_DATA,
                "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}