Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.jwusch:SmartGattLib:1.9'
}
dependencies {
implementation("com.github.jwusch:SmartGattLib:1.9")
}
<dependency>
<groupId>com.github.jwusch</groupId>
<artifactId>SmartGattLib</artifactId>
<version>1.9</version>
</dependency>
libraryDependencies += "com.github.jwusch" % "SmartGattLib" % "1.9"
:dependencies [[com.github.jwusch/SmartGattLib "1.9"]]
<a href="https://jitpack.io/#movisens/SmartGattLib/"><img src="https://img.shields.io/github/tag/movisens/SmartGattLib.svg?label=Maven%20on%20JitPack" /></a>
SmartGattLib is a Java library that simplifies the work with Bluetooth SMART devices (a.k.a. Bluetooth Low Energy in Bluetooth 4.0). It provides all UUIDs of the adopted GATT specification and an convenient way to interpret the characteristics (e.g. Heart Rate, BatteryLevel).
The library has no dependencies and can be use with every Bluetooth SMART stack e.g.:
Working with Bluetooth SMART devices is usually done in the following way:
Example Android project with SmartGattLib available here. This is a fork of the Android BluetoothLeGatt Example project. Main modifications can be found in this commit.
Add the JitPack repository and the dependency to your build file:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.movisens:SmartGattLib:1.7'
}
or download the latest .jar file from the releases page and place it in your Android app’s libs/ folder.
import com.movisens.smartgattlib.*;
// onConnected
//TODO: iterate over available services
UUID serviceUuid = service.getUuid();
if (Service.HEART_RATE.equals(serviceUuid)) { // Identify Service
//TODO: iterate over characteristics
UUID characteristicUuid = characteristic.getUuid();
if (Characteristic.HEART_RATE_MEASUREMENT.equals(characteristicUuid)) { // Identify Characteristic
// TODO: Enable notification e.g. for Android API 18:
// BluetoothGattDescriptor descriptor = characteristic.getDescriptor(Descriptor.CLIENT_CHARACTERISTIC_CONFIGURATION);
// descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
// mBluetoothGatt.writeDescriptor(descriptor);
}
}else{
System.out.println("Found unused Service: " + Service.lookup(serviceUuid, "unknown"));
}
// onCharacteristicChanged
UUID characteristicUuid = characteristic.getUuid();
if (Characteristic.HEART_RATE_MEASUREMENT.equals(characteristicUuid)) { // Identify Characteristic
byte[] value = characteristic.getValue();
HeartRateMeasurement hrm = new HeartRateMeasurement(value); // Interpret Characteristic
System.out.println("HR: " + hrm.getHr() + "bpm");
System.out.println("EE: " + hrm.getEe() + "kJ");
}
Copyright 2013 movisens GmbH
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.