├── .idea ├── .name ├── .gitignore ├── compiler.xml ├── kotlinc.xml ├── misc.xml ├── jarRepositories.xml ├── codeStyles │ └── Project.xml └── inspectionProfiles │ └── Project_Default.xml ├── app ├── .gitignore ├── src │ ├── main │ │ ├── ic_launcher-playstore.png │ │ ├── res │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── ic_error.xml │ │ │ │ ├── ic_bluetooth.xml │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── themes.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── layout │ │ │ │ ├── fragment_scan_devices.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── item_bluetooth_device.xml │ │ │ │ ├── fragment_cycle_devices.xml │ │ │ │ └── fragment_single_device.xml │ │ │ └── navigation │ │ │ │ └── main_navigation_graph.xml │ │ ├── java │ │ │ └── quevedo │ │ │ │ └── soares │ │ │ │ └── leandro │ │ │ │ └── blemadeeasy │ │ │ │ └── sampleapp │ │ │ │ ├── view │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── scandevices │ │ │ │ │ └── ScanDevicesFragment.kt │ │ │ │ ├── cycledevices │ │ │ │ │ ├── SingleDeviceFragmentTest.kt │ │ │ │ │ └── CycleDevicesFragment.kt │ │ │ │ └── singledevice │ │ │ │ │ └── SingleDeviceFragment.kt │ │ │ │ └── adapter │ │ │ │ └── BLEDeviceAdapter.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── quevedo │ │ │ └── soares │ │ │ └── leandro │ │ │ └── blemadeeasy │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── quevedo │ │ └── soares │ │ └── leandro │ │ └── blemadeeasy │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── lib ├── .gitignore ├── consumer-rules.pro ├── src │ ├── main │ │ ├── java │ │ │ └── quevedo │ │ │ │ └── soares │ │ │ │ └── leandro │ │ │ │ └── blemadeeasy │ │ │ │ ├── exceptions │ │ │ │ ├── PermissionsDeniedException.kt │ │ │ │ ├── ScanTimeoutException.kt │ │ │ │ ├── DisabledAdapterException.kt │ │ │ │ ├── ScanFailureException.kt │ │ │ │ ├── ConnectionClosingException.kt │ │ │ │ ├── PeripheralNotObservableException.kt │ │ │ │ └── HardwareNotPresentException.kt │ │ │ │ ├── typealiases │ │ │ │ └── TypeAliases.kt │ │ │ │ ├── models │ │ │ │ ├── BluetoothService.kt │ │ │ │ ├── BLEDevice.kt │ │ │ │ └── BluetoothCharacteristic.kt │ │ │ │ ├── contracts │ │ │ │ └── BluetoothAdapterContract.kt │ │ │ │ ├── enums │ │ │ │ ├── Priority.kt │ │ │ │ ├── GattState.kt │ │ │ │ └── GattStatus.kt │ │ │ │ ├── ContractHandler.kt │ │ │ │ ├── utils │ │ │ │ └── PermissionUtils.kt │ │ │ │ ├── BluetoothConnection.kt │ │ │ │ └── BLE.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── quevedo │ │ │ └── soares │ │ │ └── leandro │ │ │ └── blemadeeasy │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── quevedo │ │ └── soares │ │ └── leandro │ │ └── blemadeeasy │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── jitpack.yml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── LICENSE ├── gradle.properties ├── .gitignore ├── .github └── workflows │ └── publish.yml ├── gradlew.bat ├── gradlew └── README.md /.idea/.name: -------------------------------------------------------------------------------- 1 | blemadeeasy -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /lib/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':lib' 2 | include ':app' 3 | rootProject.name = "blemadeeasy" -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeandroSQ/android-ble-made-easy/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeandroSQ/android-ble-made-easy/HEAD/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/PermissionsDeniedException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class PermissionsDeniedException : Exception("Bluetooth permissions denied!") -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/ScanTimeoutException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class ScanTimeoutException : Exception("The scan has exceeded the time limit!") -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/DisabledAdapterException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class DisabledAdapterException : Exception("Could not turn bluetooth adapter on!") -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/ScanFailureException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class ScanFailureException(val code: Int) : Exception("Scan failed to execute!\nError code: $code") -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/ConnectionClosingException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class ConnectionClosingException : Exception("Cannot perform this operation because the connection is being closed!") -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 04 16:20:00 BRT 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/typealiases/TypeAliases.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.typealiases 2 | 3 | internal typealias EmptyCallback = () -> Unit 4 | 5 | internal typealias Callback = (T) -> Unit 6 | 7 | internal typealias PermissionRequestCallback = (granted: Boolean) -> Unit 8 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/PeripheralNotObservableException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class PeripheralNotObservableException(device: String, characteristic: String) : Exception("Device's ($device) characteristic ($characteristic) does not support property NOTIFY") -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/exceptions/HardwareNotPresentException.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.exceptions 2 | 3 | class HardwareNotPresentException : Exception("Bluetooth and/or Bluetooth Low Energy feature not found!\nDid you forgot to enable it on manifest.xml?\n\nIf running on an Emulator, emulators usually do not provide BLE hardware emulation, please try with a physical device.") -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_error.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/test/java/quevedo/soares/leandro/blemadeeasy/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /lib/src/test/java/quevedo/soares/leandro/blemadeeasy/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/models/BluetoothService.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.models 2 | 3 | import android.bluetooth.BluetoothGattService 4 | 5 | data class BluetoothService( 6 | private val service: BluetoothGattService, 7 | ) { 8 | val isPrimary get() = this.service.type == BluetoothGattService.SERVICE_TYPE_PRIMARY 9 | val isSecondary get() = this.service.type == BluetoothGattService.SERVICE_TYPE_SECONDARY 10 | val characteristics get() = this.service.characteristics.map { BluetoothCharacteristic(it) } 11 | } -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/models/BLEDevice.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.models 2 | 3 | import android.annotation.SuppressLint 4 | import android.bluetooth.BluetoothDevice 5 | 6 | class BLEDevice(var device: BluetoothDevice, var rsii: Int = 0, val advertisingId: Int = -1) { 7 | 8 | @get:SuppressLint("MissingPermission") 9 | val name: String 10 | get() = device.name ?: "" 11 | 12 | val macAddress: String get () = device.address 13 | 14 | override fun toString(): String = "$name - $macAddress - ${rsii}dBm" 15 | 16 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_bluetooth.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF9800 9 | #FF5722 10 | #90CAF9 11 | #1976D2 12 | #157AE5 13 | #1A63AF 14 | #FF000000 15 | #FFFFFFFF 16 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/contracts/BluetoothAdapterContract.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.contracts 2 | 3 | import android.app.Activity 4 | import android.bluetooth.BluetoothAdapter 5 | import android.content.Context 6 | import android.content.Intent 7 | import androidx.activity.result.contract.ActivityResultContract 8 | 9 | /** 10 | * Custom Contract to determine whether a Bluetooth activation request is fulfilled 11 | * 12 | * Resulting in a boolean, true when success 13 | **/ 14 | class BluetoothAdapterContract: ActivityResultContract() { 15 | 16 | override fun createIntent(context: Context, input: Unit): Intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE) 17 | 18 | override fun parseResult(resultCode: Int, intent: Intent?): Boolean = resultCode == Activity.RESULT_OK 19 | 20 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/quevedo/soares/leandro/blemadeeasy/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | 19 | @Test 20 | fun useAppContext() { 21 | // Context of the app under test. 22 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 23 | assertEquals("quevedo.soares.leandro.blemadeeasy", appContext.packageName) 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /lib/src/androidTest/java/quevedo/soares/leandro/blemadeeasy/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("quevedo.soares.leandro.blemadeeasy.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/enums/Priority.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.enums 2 | 3 | import android.bluetooth.BluetoothGatt 4 | 5 | enum class Priority { 6 | /** Request low power, reduced data rate connection parameters. */ 7 | LowPower, 8 | /** Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested. */ 9 | Balanced, 10 | /** Request a high priority, low latency connection. An application should only request high priority connection parameters to transfer large amounts of data over LE quickly. Once the transfer is complete, the application should request [Balanced] connection parameters to reduce energy use. */ 11 | High; 12 | 13 | internal fun toGattEnum(): Int { 14 | return when (this) { 15 | LowPower -> BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER 16 | Balanced -> BluetoothGatt.CONNECTION_PRIORITY_BALANCED 17 | High -> BluetoothGatt.CONNECTION_PRIORITY_HIGH 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BLE Made Easy 3 | 4 | 5 | TOGGLE 6 | OBSERVE 7 | STOP OBSERVING 8 | READ 9 | DISCONNECT 10 | CONNECT 11 | Loading 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Bluetooth icon 20 | 21 | 22 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/enums/GattState.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.enums 2 | 3 | /** 4 | * Represents the GATT possible states 5 | * 6 | * @property code The code of the state 7 | * @property description The description of the state 8 | * 9 | * @see https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_CONNECTED 10 | */ 11 | enum class GattState(val code: Int, val description: String) { 12 | Unknown(-1, "Unknown"), 13 | Disconnected(0, "Disconnected"), 14 | Connecting(1, "Connecting"), 15 | Connected(2, "Connected"), 16 | Disconnecting(3, "Disconnecting"); 17 | 18 | override fun toString() = "Code: $code - State.$name - $description" 19 | 20 | companion object { 21 | /** 22 | * Returns the GattState for the given code 23 | * 24 | * @param code The code to be converted 25 | * @return The GattState for the given code 26 | */ 27 | fun fromCode(code: Int) = values().find { it.code == code } ?: Unknown 28 | } 29 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Leandro SQ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 23 | 24 | -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 12 | 13 | 14 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/quevedo/soares/leandro/blemadeeasy/sampleapp/view/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.sampleapp.view 2 | 3 | import android.os.Bundle 4 | import android.os.PersistableBundle 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.navigation.findNavController 7 | import androidx.navigation.ui.AppBarConfiguration 8 | import androidx.navigation.ui.setupWithNavController 9 | import quevedo.soares.leandro.blemadeeasy.sampleapp.R 10 | import quevedo.soares.leandro.blemadeeasy.sampleapp.databinding.ActivityMainBinding 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | private val navController by lazy { findNavController(R.id.home) } 15 | private lateinit var binding: ActivityMainBinding 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | 20 | this.binding = ActivityMainBinding.inflate(layoutInflater) 21 | setContentView(this.binding.root) 22 | } 23 | 24 | override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { 25 | super.onPostCreate(savedInstanceState, persistentState) 26 | 27 | this.binding.amMtToolbar.setupWithNavController(this.navController, AppBarConfiguration(setOf())) 28 | } 29 | 30 | override fun onSupportNavigateUp(): Boolean = navController.navigateUp() 31 | 32 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | android.defaults.buildfeatures.buildconfig=true 23 | android.nonTransitiveRClass=false 24 | android.nonFinalResIds=false -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_scan_devices.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/navigation/main_navigation_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 17 | 18 | 21 | 22 | 23 | 24 | 29 | 30 | 35 | 36 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/ContractHandler.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy 2 | 3 | import androidx.activity.ComponentActivity 4 | import androidx.activity.result.ActivityResultLauncher 5 | import androidx.activity.result.contract.ActivityResultContract 6 | import androidx.appcompat.app.AppCompatActivity 7 | import androidx.fragment.app.Fragment 8 | import quevedo.soares.leandro.blemadeeasy.typealiases.Callback 9 | 10 | class ContractHandler(contract: ActivityResultContract, componentActivity: ComponentActivity?, activity: AppCompatActivity?, fragment: Fragment?) { 11 | 12 | private var activityResultLauncher: ActivityResultLauncher? = null 13 | private var callback: Callback? = null 14 | 15 | init { 16 | when { 17 | // Jetpack compose 18 | componentActivity != null -> this.activityResultLauncher = componentActivity.registerForActivityResult(contract, this::onContractResult) 19 | 20 | // AppCompatActivity 21 | activity != null -> this.activityResultLauncher = activity.registerForActivityResult(contract, this::onContractResult) 22 | 23 | // Fragment 24 | fragment != null -> this.activityResultLauncher = fragment.registerForActivityResult(contract, this::onContractResult) 25 | } 26 | } 27 | 28 | private fun onContractResult(output: O) { 29 | callback?.invoke(output) 30 | } 31 | 32 | fun launch(input: I) { 33 | this.activityResultLauncher?.launch(input) 34 | } 35 | 36 | fun launch(input: I, callback: Callback) { 37 | this.callback = callback 38 | this.activityResultLauncher?.launch(input) 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | docs/ 8 | 9 | # Files for the ART/Dalvik VM 10 | *.dex 11 | 12 | # Java class files 13 | *.class 14 | 15 | # Generated files 16 | bin/ 17 | gen/ 18 | out/ 19 | # Uncomment the following line in case you need and you don't have the release build type files in your app 20 | # release/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | # Local configuration file (sdk path, etc) 27 | local.properties 28 | 29 | # Proguard folder generated by Eclipse 30 | proguard/ 31 | 32 | # Log Files 33 | *.log 34 | 35 | # Android Studio Navigation editor temp files 36 | .navigation/ 37 | 38 | # Android Studio captures folder 39 | captures/ 40 | 41 | # IntelliJ 42 | *.iml 43 | .idea/workspace.xml 44 | .idea/tasks.xml 45 | .idea/gradle.xml 46 | .idea/assetWizardSettings.xml 47 | .idea/dictionaries 48 | .idea/libraries 49 | # Android Studio 3 in .gitignore file. 50 | .idea/caches 51 | .idea/modules.xml 52 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 53 | .idea/navEditor.xml 54 | 55 | # Keystore files 56 | # Uncomment the following lines if you do not want to check your keystore files in. 57 | #*.jks 58 | #*.keystore 59 | 60 | # External native build folder generated in Android Studio 2.2 and later 61 | .externalNativeBuild 62 | .cxx/ 63 | 64 | # Google Services (e.g. APIs or Firebase) 65 | # google-services.json 66 | 67 | # Freeline 68 | freeline.py 69 | freeline/ 70 | freeline_project_description.json 71 | 72 | # fastlane 73 | fastlane/report.xml 74 | fastlane/Preview.html 75 | fastlane/screenshots 76 | fastlane/test_output 77 | fastlane/readme.md 78 | 79 | # Version control 80 | vcs.xml 81 | 82 | # lint 83 | lint/intermediates/ 84 | lint/generated/ 85 | lint/outputs/ 86 | lint/tmp/ 87 | # lint/reports/ 88 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 12 | 13 | 14 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish a new version for the library 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | persist-credentials: false 17 | fetch-depth: 0 18 | 19 | - uses: actions/setup-java@v3.13.0 20 | with: 21 | java-version: 17 22 | distribution: temurin 23 | 24 | - name: Grant execute permission for gradlew 25 | run: chmod +x gradlew 26 | 27 | - name: Build the library 28 | run: ./gradlew lib:build 29 | 30 | - name: Update README.md version 31 | run: ./gradlew lib:updateReadmeVersion 32 | 33 | - name: Check if the README.md version was updated correctly 34 | shell: bash 35 | run: | 36 | FILE="README.md" 37 | PATTERN="implementation 'com\.github\.LeandroSQ:android-ble-made-easy:([0-9]+\.[0-9]+\.[0-9]+)'" 38 | if [[ $(cat $FILE) =~ $PATTERN ]]; then 39 | VERSION="${BASH_REMATCH[1]}" 40 | echo $VERSION 41 | else 42 | echo "Error: Could not find version number in $FILE." >&2 43 | exit 1 44 | fi 45 | 46 | - name: Publish to Jitpack 47 | run: ./gradlew lib:publish 48 | 49 | - name: Generate Documentation with Dokka 50 | run: | 51 | ./gradlew lib:dokkaHtml 52 | echo "Deleting old documentation files" 53 | rm -rf ./docs 54 | echo "Moving generated documentation files" 55 | mv -f lib/build/dokka/html ./docs 56 | 57 | - name: Deploy to GitHub Pages 58 | uses: JamesIves/github-pages-deploy-action@v4.2.5 59 | with: 60 | branch: gh-pages 61 | folder: docs -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 26 | 27 | 28 | 29 | 30 | 31 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | id 'androidx.navigation.safeargs' 6 | } 7 | 8 | android { 9 | compileSdk 34 10 | 11 | defaultConfig { 12 | applicationId "quevedo.soares.leandro.blemadeeasy.sampleapp" 13 | minSdkVersion 21 14 | targetSdkVersion 33 15 | versionCode 2 16 | versionName "1.5" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | } 20 | 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_17 23 | targetCompatibility JavaVersion.VERSION_17 24 | } 25 | 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | 33 | buildFeatures { 34 | viewBinding true 35 | } 36 | 37 | packagingOptions { 38 | resources { 39 | excludes += '/META-INF/{AL2.0,LGPL2.1,NOTICE.md,LICENSE.md}' 40 | } 41 | } 42 | 43 | namespace 'quevedo.soares.leandro.blemadeeasy.sampleapp' 44 | } 45 | 46 | dependencies { 47 | implementation project(":lib") 48 | 49 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 50 | implementation 'androidx.core:core-ktx:1.12.0' 51 | implementation 'androidx.appcompat:appcompat:1.6.1' 52 | implementation 'com.google.android.material:material:1.10.0' 53 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 54 | 55 | /* Contracts */ 56 | implementation 'androidx.activity:activity-ktx:1.8.0' 57 | implementation 'androidx.fragment:fragment-ktx:1.6.1' 58 | 59 | /* Navigation */ 60 | implementation "androidx.navigation:navigation-fragment-ktx:2.7.4" 61 | implementation "androidx.navigation:navigation-ui-ktx:2.7.4" 62 | implementation "androidx.navigation:navigation-dynamic-features-fragment:2.7.4" 63 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 64 | 65 | testImplementation 'junit:junit:4.13.2' 66 | androidTestImplementation 'androidx.test.ext:junit:1.1.5' 67 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 68 | } -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/utils/PermissionUtils.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.utils 2 | 3 | import android.Manifest.* 4 | import android.app.Activity 5 | import android.content.Context 6 | import android.content.pm.PackageManager 7 | import android.os.Build 8 | import androidx.annotation.ChecksSdkIntAtLeast 9 | import androidx.annotation.RequiresApi 10 | import androidx.core.content.ContextCompat 11 | 12 | internal object PermissionUtils { 13 | 14 | @RequiresApi(Build.VERSION_CODES.S) 15 | private val android12Permissions = arrayOf(permission.BLUETOOTH_CONNECT, permission.BLUETOOTH_SCAN) 16 | 17 | @RequiresApi(Build.VERSION_CODES.Q) 18 | private val android10Permissions = arrayOf(permission.ACCESS_BACKGROUND_LOCATION) 19 | 20 | private val legacyPermissions = arrayOf(permission.BLUETOOTH, permission.BLUETOOTH_ADMIN) 21 | private val locationPermissions = arrayOf(permission.ACCESS_FINE_LOCATION, permission.ACCESS_COARSE_LOCATION) 22 | 23 | val permissions by lazy { 24 | val list = arrayListOf() 25 | 26 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { 27 | list.addAll(android12Permissions) 28 | } else { 29 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) list.addAll(android10Permissions) 30 | 31 | list.addAll(legacyPermissions) 32 | list.addAll(locationPermissions) 33 | } 34 | 35 | list.toTypedArray() 36 | } 37 | 38 | fun isBluetoothLowEnergyPresentOnDevice(packageManager: PackageManager): Boolean { 39 | return packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) 40 | } 41 | 42 | fun isBluetoothPresentOnDevice(packageManager: PackageManager): Boolean { 43 | return packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH) 44 | } 45 | 46 | @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.M) 47 | private fun isPermissionRequestRequired() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M 48 | 49 | private fun isPermissionGranted(context: Context, permission: String): Boolean { 50 | if (!isPermissionRequestRequired()) return true 51 | 52 | return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED 53 | } 54 | 55 | fun isEveryBluetoothPermissionsGranted(context: Context) = permissions.all { isPermissionGranted(context, it) } 56 | 57 | fun isPermissionRationaleNeeded(context: Activity): Boolean { 58 | if (!isPermissionRequestRequired()) return false 59 | 60 | return permissions.any { context.shouldShowRequestPermissionRationale(it) } 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_bluetooth_device.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 24 | 25 | 39 | 40 | 55 | 56 | 71 | 72 | -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/models/BluetoothCharacteristic.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.models 2 | 3 | import android.Manifest 4 | import android.annotation.SuppressLint 5 | import android.bluetooth.BluetoothGatt 6 | import android.bluetooth.BluetoothGattCharacteristic 7 | import android.bluetooth.BluetoothGattDescriptor 8 | import androidx.annotation.RequiresPermission 9 | import quevedo.soares.leandro.blemadeeasy.exceptions.PeripheralNotObservableException 10 | import java.util.* 11 | 12 | data class BluetoothCharacteristic( 13 | private val characteristic: BluetoothGattCharacteristic 14 | ) { 15 | val descriptors get() = this.characteristic.descriptors 16 | val isWritable get() = this.characteristic.properties and BluetoothGattCharacteristic.PROPERTY_WRITE != 0 17 | val isReadable get() = this.characteristic.properties and BluetoothGattCharacteristic.PROPERTY_READ != 0 18 | val isNotifiable get() = this.characteristic.properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY != 0 19 | val uuid get() = this.characteristic.uuid 20 | 21 | fun getDescriptor(characteristic: String): BluetoothGattDescriptor? { 22 | val c = UUID.fromString(characteristic) 23 | return this.characteristic.descriptors.find { it.uuid == c } 24 | } 25 | 26 | @SuppressLint("MissingPermission") 27 | fun read(gatt: BluetoothGatt): Boolean = gatt.readCharacteristic(this.characteristic) 28 | 29 | @SuppressLint("MissingPermission") 30 | fun write(gatt: BluetoothGatt, value: ByteArray): Boolean { 31 | this.characteristic.value = value 32 | return gatt.writeCharacteristic(this.characteristic) 33 | } 34 | 35 | @SuppressLint("MissingPermission") 36 | fun enableNotify(gatt: BluetoothGatt) { 37 | // If the characteristic does not export the NOTIFY property, throw an exception 38 | if (!this.isNotifiable) throw PeripheralNotObservableException(gatt.device.address, this.uuid.toString().lowercase()) 39 | 40 | this.descriptors.firstOrNull()?.let { 41 | it.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE 42 | gatt.writeDescriptor(it) 43 | } 44 | 45 | gatt.setCharacteristicNotification(this.characteristic, true) 46 | } 47 | 48 | @SuppressLint("MissingPermission") 49 | fun disableNotify(gatt: BluetoothGatt) { 50 | // If the characteristic does not export the NOTIFY property, throw an exception 51 | if (!this.isNotifiable) throw PeripheralNotObservableException(gatt.device.address, this.uuid.toString().lowercase()) 52 | 53 | this.descriptors.firstOrNull()?.let { 54 | it.value = byteArrayOf(0, 0) 55 | gatt.writeDescriptor(it) 56 | } 57 | 58 | gatt.setCharacteristicNotification(this.characteristic, false) 59 | } 60 | 61 | fun checkUuid(uuid: UUID): Boolean { 62 | if (this.uuid == uuid) return true 63 | 64 | if (this.descriptors.any { it.uuid == uuid }) return true 65 | 66 | return false 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /lib/src/main/java/quevedo/soares/leandro/blemadeeasy/enums/GattStatus.kt: -------------------------------------------------------------------------------- 1 | package quevedo.soares.leandro.blemadeeasy.enums 2 | 3 | /** 4 | * Represents the GATT possible status codes 5 | * 6 | * @property code The code of the status 7 | * @property description The description of the status 8 | * 9 | * @see https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/gatt_api.h;l=543;drc=6cf6099dcab87865e33439215e7ea0087e60c9f2#:~:text=/*%20Success%20code%20and%20error%20codes%20*/ 10 | */ 11 | enum class GattStatus(val code: Int, val description: String) { 12 | Unknown(-1, "Unknown"), 13 | InvalidHandle(1, "Invalid handle"), 14 | ReadNotPermitted(2, "Read not permitted"), 15 | WriteNotPermitted(3, "Write not permitted"), 16 | InvalidPdu(4, "Invalid PDU"), 17 | InsufficientAuthentication(5, "Insufficient authentication"), 18 | RequestNotSupported(6, "Request not supported"), 19 | InvalidOffset(7, "Invalid offset"), 20 | InsufficientAuthorization(8, "Insufficient authorization"), 21 | PrepareQueueFull(9, "Prepare queue full"), 22 | AttributeNotFound(10, "Attribute not found"), 23 | AttributeNotLong(11, "Attribute not long"), 24 | InsufficientEncryptionKeySize(12, "Insufficient encryption key size"), 25 | InvalidAttributeValueLength(13, "Invalid attribute value length"), 26 | UnlikelyError(14, "Unlikely error"), 27 | InsufficientEncryption(15, "Insufficient encryption"), 28 | UnsupportedGroupType(16, "Unsupported group type"), 29 | InsufficientResources(17, "Insufficient resources"), 30 | DatabaseOutOfSync(18, "Database out of sync"), 31 | NoResources(128, "No resources"), 32 | InternalError(129, "Internal error"), 33 | WrongState(130, "Wrong state"), 34 | DbFull(131, "Database full"), 35 | Busy(132, "Busy"), 36 | Error(133, "Error"), 37 | CmdStarted(134, "Command started"), 38 | IllegalParameter(135, "Illegal parameter"), 39 | Pending(136, "Pending"), 40 | AuthFail(137, "Authentication failure"), 41 | More(138, "More"), 42 | InvalidConfiguration(139, "Invalid configuration"), 43 | ServiceStarted(140, "Service started"), 44 | EncryptedNoMitm(141, "Encrypted no MITM"), 45 | NotEncrypted(142, "Not encrypted"), 46 | Congested(143, "Congested"), 47 | CccCfgError(253, "CCC config error"), 48 | PrcInProgress(254, "Procedure in progress"), 49 | ValueOutOfRange(255, "Value out of range"), 50 | ConnectionCancel(256, "Connection Cancelled"), 51 | Failure(257, "Failure"); 52 | 53 | override fun toString() = "Code: $code - Status.$name - $description" 54 | 55 | companion object { 56 | /** 57 | * Returns the GattStatus for the given code 58 | * 59 | * @param code The code to be converted 60 | * @return The GattStatus for the given code 61 | */ 62 | fun fromCode(code: Int) = values().find { it.code == code } ?: Unknown 63 | 64 | } 65 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_cycle_devices.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 22 | 23 | 32 | 33 |