Android Open Source - BLEService B T Service Profile

From Project

Back to project page BLEService.


The source code is released under:

Copyright (c) 2014, Ratio LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project BLEService listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ratio.deviceService;
//from   w w 2  s  .  c o  m
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.ratio.util.UUIDUtils;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.os.Parcel;
import android.os.Parcelable;

 * external description of a device profile, so once we query the device services and characteristics
 * we can send it back from the service to the activity in a bundle, which can be received by the BroadcastReceiver
 * @author mreynolds

public class BTServiceProfile implements Parcelable {
  public BluetoothGattService          mService;
  public BTServiceProfile(BluetoothGattService service) {
    mService = service;

  public BluetoothGattService getService() {
    return mService;
  public static List<BluetoothGattService> getServiceList(List<BTServiceProfile> profileList) {
    List<BluetoothGattService> serviceList = new ArrayList<BluetoothGattService>(profileList.size());
    for (BTServiceProfile profile : profileList) {
    return serviceList;
  public BTServiceProfile(Parcel in) {
    UUID serviceUUID = UUIDUtils.readFromParcel(in);
    int type = in.readInt();
    int numCharacteristics = in.readInt();
    mService = new BluetoothGattService(serviceUUID, type);
    for (int i = 0; i < numCharacteristics; i++) {
      BTCharacteristicProfile profile = new BTCharacteristicProfile(in);
  public int describeContents() {
    return 0;
  public void writeToParcel(Parcel dest, int flags) {
    UUIDUtils.writeToParcel(mService.getUuid(), dest);
    for (BluetoothGattCharacteristic characteristic : mService.getCharacteristics()) {
      BTCharacteristicProfile profile = new BTCharacteristicProfile(characteristic);
      profile.writeToParcel(dest, flags);
  public static final Parcelable.Creator<BTServiceProfile> CREATOR = 
        new Parcelable.Creator<BTServiceProfile>() {

            public BTServiceProfile createFromParcel(Parcel source) {
                return new BTServiceProfile(source);

            public BTServiceProfile[] newArray(int size) {
                return new BTServiceProfile[size];

Java Source Code List