Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #36 from g-ortuno/broadcast-service-uuid
Browse files Browse the repository at this point in the history
Peripherals now broadcast their service UUID.
  • Loading branch information
g-ortuno committed May 6, 2015
2 parents 6d47d69 + edc5df8 commit cb6787f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
Expand Up @@ -20,6 +20,7 @@
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -155,6 +156,11 @@ public BluetoothGattService getBluetoothGattService() {
return mBatteryService;
}

@Override
public ParcelUuid getServiceUUID() {
return new ParcelUuid(BATTERY_SERVICE_UUID);
}

private void setBatteryLevel(int newBatteryLevel, View source) {
mBatteryLevelCharacteristic.setValue(newBatteryLevel,
BluetoothGattCharacteristic.FORMAT_UINT8, /* offset */ 0);
Expand Down
Expand Up @@ -21,6 +21,7 @@
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -216,6 +217,11 @@ public BluetoothGattService getBluetoothGattService() {
return mHeartRateService;
}

@Override
public ParcelUuid getServiceUUID() {
return new ParcelUuid(HEART_RATE_SERVICE_UUID);
}

private void setHeartRateMeasurementValue(int heartRateMeasurementValue, int expendedEnergy) {

Log.d(TAG, Arrays.toString(mHeartRateMeasurementCharacteristic.getValue()));
Expand Down
Expand Up @@ -206,6 +206,7 @@ protected void onCreate(Bundle savedInstanceState) {
mAdvData = new AdvertiseData.Builder()
.setIncludeDeviceName(true)
.setIncludeTxPowerLevel(true)
.addServiceUuid(mCurrentServiceFragment.getServiceUUID())
.build();
}

Expand Down
Expand Up @@ -19,9 +19,11 @@
import android.app.Fragment;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.os.ParcelUuid;

public abstract class ServiceFragment extends Fragment{
public abstract BluetoothGattService getBluetoothGattService();
public abstract ParcelUuid getServiceUUID();

/**
* Function to communicate to the ServiceFragment that a device wants to write to a
Expand Down

0 comments on commit cb6787f

Please sign in to comment.