Example usage for android.bluetooth BluetoothGattCharacteristic PROPERTY_NOTIFY

List of usage examples for android.bluetooth BluetoothGattCharacteristic PROPERTY_NOTIFY

Introduction

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

Prototype

int PROPERTY_NOTIFY

To view the source code for android.bluetooth BluetoothGattCharacteristic PROPERTY_NOTIFY.

Click Source Link

Document

Characteristic property: Characteristic supports notification

Usage

From source file:com.cypress.cysmart.GATTDBFragments.GattDescriptorDetails.java

/**
 * Preparing Broadcast receiver to broadcast notify characteristics
 *
 * @param gattCharacteristic//ww  w.  j  a  va 2  s  . c om
 */
void prepareBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) {
    Logger.i("Notify called");
    final BluetoothGattCharacteristic characteristic = gattCharacteristic;
    final int charaProp = characteristic.getProperties();
    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        BluetoothLeService.setCharacteristicNotification(characteristic, true);

    }

}

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

/**
 * Stopping Broadcast receiver to broadcast notify characteristics
 *
 * @param gattCharacteristic/*  www  .jav  a 2 s  . c  om*/
 */
void stopBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) {
    final int charaProp = gattCharacteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        if (mNotifyCharacteristic != null) {
            Logger.d("Stopped notification");
            BluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false);
            mNotifyCharacteristic = null;
        }

    }

}

From source file:com.cypress.cysmart.GATTDBFragments.GattDescriptorDetails.java

/**
 * Stopping Broadcast receiver to broadcast notify characteristics
 *
 * @param gattCharacteristic//  ww w . j av a2s.  c o m
 */
void stopBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) {
    Logger.i("Notify stopped");
    final BluetoothGattCharacteristic characteristic = gattCharacteristic;
    final int charaProp = characteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        if (gattCharacteristic != null) {
            BluetoothLeService.setCharacteristicNotification(gattCharacteristic, false);
        }

    }

}

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

/**
 * Stopping Broadcast receiver to broadcast notify characteristics
 *
 * @param gattCharacteristic/*from   w w  w.  ja  v a 2 s  . c o m*/
 */
void stopBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) {
    final int charaProp = gattCharacteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        if (mNotifyCharacteristic != null) {
            Logger.d("Stopped notification");
            BluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false);
            mNotifyCharacteristic = null;
        }

    }
}

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

/**
 * Preparing Broadcast receiver to broadcast notify characteristics
 *
 * @param gattCharacteristic/*  w  ww . j a  va2s.  com*/
 */
void prepareBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) {
    final int charaProp = gattCharacteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        mNotifyCharacteristic = gattCharacteristic;
        BluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
    }

}

From source file:com.muggins.test.ble.DeviceControlActivity.java

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;/*from w  w w.  java  2  s . c  om*/
    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>();
        if (SampleGattAttributes.SERVICE_NUMBER.equals(gattService.getUuid().toString())) {
            uuid = gattService.getUuid().toString();

            //                currentServiceData.put(LIST_NAME, "?");
            //                currentServiceData.put(LIST_UUID, "??1234");
            //                gattServiceData.add(currentServiceData);

            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>();
                if (SampleGattAttributes.HEART_RATE_MEASUREMENT
                        .equals(gattCharacteristic.getUuid().toString())) {
                    uuid = gattCharacteristic.getUuid().toString();

                    currentCharaData.put(LIST_NAME, "?");
                    currentCharaData.put(LIST_UUID, "");
                    gattCharacteristicGroupData.add(currentCharaData);

                    final int charaProp = gattCharacteristic.getProperties();
                    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
                        // If there is an active notification on a characteristic, clear
                        // it first so it doesn't update the data field on the user interface.
                        Log.e("BluetoothLeService", "read");
                        if (mNotifyCharacteristic != null) {
                            mBluetoothLeService.setCharacteristicNotification(
                                    //                                        mNotifyCharacteristic, false);
                                    mNotifyCharacteristic, true);
                            mNotifyCharacteristic = null;
                        }
                        mBluetoothLeService.readCharacteristic(gattCharacteristic);
                        //                            Intent intent = new Intent(DeviceControlActivity.this, ShowWave.class);
                        //                            startActivity(intent);
                    }
                    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
                        Log.e("BluetoothLeService", "notify");
                        mNotifyCharacteristic = gattCharacteristic;
                        mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
                    }

                }
            }
            mGattCharacteristics.add(charas);
            gattCharacteristicData.add(gattCharacteristicGroupData);
        }
    }

    SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(this, gattServiceData,
            android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID },
            new int[] { android.R.id.text1, android.R.id.text2 }, gattCharacteristicData,
            android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID },
            new int[] { android.R.id.text1, android.R.id.text2 });
    mGattServicesList.setAdapter(gattServiceAdapter);
}

From source file:com.touchKin.touchkinapp.DeviceControlActivity.java

private void readHeartRate() {
    // TODO Auto-generated method stub
    if (mConnected) {
        if (mBluetoothLeService.getSupportedGattService() != null) {
            Log.d("Read", "+++++++++++++Reading" + mBluetoothLeService.getSupportedGattService()
                    .getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123")));
            Toast.makeText(this,
                    "" + mBluetoothLeService.getSupportedGattService()
                            .getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123")),
                    Toast.LENGTH_LONG).show();
            BluetoothGattCharacteristic charprop = mBluetoothLeService.getSupportedGattService()
                    .getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123"));
            if (charprop != null) {
                final int charaProp = charprop.getProperties();
                if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
                    mNotifyCharacteristic = charprop;
                    mBluetoothLeService.setCharacteristicNotification(charprop, true);
                }/*ww w. j a va2 s  . com*/
            } else {
                Toast.makeText(this, "Unable to connect " + charprop, Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(this, "Unable to connect", Toast.LENGTH_LONG).show();
        }
    }
}

From source file:net.kenevans.android.blecardiacmonitor.BCMBleService.java

/**
 * Writes READ, NOTIFY, WRITE properties to the Log. Use for debugging.
 *
 * @param charBat    The BAT characteristic.
 * @param charHr     The HR characteristic.
 * @param charCustom The custom characteristic.
 *//* w ww. j ava2 s .c  o  m*/
@SuppressWarnings("unused")
public void checkPermissions(BluetoothGattCharacteristic charBat, BluetoothGattCharacteristic charHr,
        BluetoothGattCharacteristic charCustom) {
    // DEBUG
    // Check permissions
    if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
        Log.d(TAG, "incrementSessionState: charBat: Not Readable");
    } else {
        Log.d(TAG, "incrementSessionState: charBat: Readable");
    }
    if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) {
        Log.d(TAG, "incrementSessionState: charBat: Not Notifiable");
    } else {
        Log.d(TAG, "incrementSessionState: charBat: Notifiable");
    }
    if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) {
        Log.d(TAG, "incrementSessionState: charBat: Not Writable");
    } else {
        Log.d(TAG, "incrementSessionState: charBat: Writable");
    }

    if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
        Log.d(TAG, "incrementSessionState: charHr: Not Readable");
    } else {
        Log.d(TAG, "incrementSessionState: charHr: Readable");
    }
    if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) {
        Log.d(TAG, "incrementSessionState: charHr: Not Notifiable");
    } else {
        Log.d(TAG, "incrementSessionState: charHr: Notifiable");
    }
    if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) {
        Log.d(TAG, "incrementSessionState: charHr: Not Writable");
    } else {
        Log.d(TAG, "incrementSessionState: charHr: Writable");
    }

    if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
        Log.d(TAG, "incrementSessionState: charCustom: Not Readable");
    } else {
        Log.d(TAG, "incrementSessionState: charCustom: Readable");
    }
    if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) {
        Log.d(TAG, "incrementSessionState: charCustom: Not Notifiable");
    } else {
        Log.d(TAG, "incrementSessionState: charCustom: Notifiable");
    }
    if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) {
        Log.d(TAG, "incrementSessionState: charCustom: Not Writable");
    } else {
        Log.d(TAG, "incrementSessionState: charCustom: Writable");
    }
}

From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java

/**
 * stop notifications of all Report characteristc
 *///  ww  w.  ja va2  s .c o  m
private void stopBroadcastAllNotifications() {
    List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics();
    for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
        String uuidchara = gattCharacteristic.getUuid().toString();
        if (uuidchara.equalsIgnoreCase(GattAttributes.REP0RT)) {
            final int charaProp = gattCharacteristic.getProperties();
            if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
                BluetoothLeService.setCharacteristicNotification(gattCharacteristic, false);

            }
        }
    }
}