Android Open Source - BLEService B T Service Profile






From Project

Back to project page BLEService.

License

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  w.java 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) {
      serviceList.add(profile.getService());
    }
    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);
      mService.addCharacteristic(profile.mCharacteristic);
    }
  }
  
  @Override
  public int describeContents() {
    return 0;
  }
  
  @Override
  public void writeToParcel(Parcel dest, int flags) {
    UUIDUtils.writeToParcel(mService.getUuid(), dest);
    dest.writeInt(mService.getType());
    dest.writeInt(mService.getCharacteristics().size());
    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>() {

            @Override
            public BTServiceProfile createFromParcel(Parcel source) {
                return new BTServiceProfile(source);
            }

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




Java Source Code List

com.ratio.btdemo.BleDefinedUUIDs.java
com.ratio.btdemo.BleNamesResolver.java
com.ratio.btdemo.CharacteristicDetailsActivity.java
com.ratio.btdemo.CharacteristicsActivity.java
com.ratio.btdemo.ScanActivity.java
com.ratio.btdemo.ServicesActivity.java
com.ratio.btdemo.adapters.CharacteristicsListAdapter.java
com.ratio.btdemo.adapters.ServicesListAdapter.java
com.ratio.deviceService.BTCharacteristicProfile.java
com.ratio.deviceService.BTDescriptorProfile.java
com.ratio.deviceService.BTDeviceProfile.java
com.ratio.deviceService.BTLEDeviceManager.java
com.ratio.deviceService.BTServiceProfile.java
com.ratio.deviceService.BTUUID.java
com.ratio.deviceService.BluetoothBroadcastReceiver.java
com.ratio.deviceService.DeviceErrorCodes.java
com.ratio.deviceService.DeviceService.java
com.ratio.deviceService.command.BTLECommandDisconnect.java
com.ratio.deviceService.command.BTLECommandDiscoverServices.java
com.ratio.deviceService.command.BTLECommandReadCharacteristic.java
com.ratio.deviceService.command.BTLECommandReadDescriptor.java
com.ratio.deviceService.command.BTLECommandSetCharacteristicNotification.java
com.ratio.deviceService.command.BTLECommandWriteCharacteristic.java
com.ratio.deviceService.command.BTLECommandWriteDescriptor.java
com.ratio.deviceService.command.BTLECommand.java
com.ratio.deviceService.receivers.CharacteristicReceiver.java
com.ratio.deviceService.receivers.CharactertisticListReceiver.java
com.ratio.deviceService.receivers.ConnectionStateReceiver.java
com.ratio.deviceService.receivers.DescriptorReceiver.java
com.ratio.deviceService.receivers.DeviceDiscoveredRecevier.java
com.ratio.deviceService.receivers.RSSIReceiver.java
com.ratio.deviceService.receivers.ServicesDiscoveredReceiver.java
com.ratio.exceptions.DeviceManagerException.java
com.ratio.exceptions.DeviceNameNotFoundException.java
com.ratio.util.BitUtils.java
com.ratio.util.StringUtil.java
com.ratio.util.UUIDUtils.java
org.bluetooth.bledemo.BleDefinedUUIDs.java
org.bluetooth.bledemo.BleNamesResolver.java
org.bluetooth.bledemo.BleWrapperUiCallbacks.java
org.bluetooth.bledemo.BleWrapper.java
org.bluetooth.bledemo.CharacteristicDetailsAdapter.java
org.bluetooth.bledemo.CharacteristicsListAdapter.java
org.bluetooth.bledemo.DeviceListAdapter.java
org.bluetooth.bledemo.HRDemoActivity.java
org.bluetooth.bledemo.PeripheralActivity.java
org.bluetooth.bledemo.ScanningActivity.java
org.bluetooth.bledemo.ServicesListAdapter.java