Android Bluetooth Helper Library, Bluetooth Device Finder

Overview

Bluetooth Helper

API ktlint Kotlin MIT License Android Arsenal

Allows you to access the Bluetooth of your mobile device, manage turn-on - turn off, and discover bluetooth devices around you.

Alt Text

Getting started

Setup

Step 1. Add the required permissions to the AndroidManifest.xml file
  • Add Bluetooth permissions to your AndroidManifest.xml:
<uses-permission android:name = "android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name = "android.permission.BLUETOOTH"/>
  • if you want to access the device list, you must add the following to the AndroidManifest.xml file in the location permissions:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Step 2. Add the JitPack repository to your build file
  • Add it in your root build.gradle at the end of repositories:
allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}
Step 3. Add the dependency
  • Add it in app build.gradle
dependencies {
	        implementation 'com.github.tlgbltcn:BluetoothHelper:v1.0'
	}

Usage

  • If you want to get a list of the bluetooth devices around you, you should use setPermission (true). Automatically request location permission for you
   val bluetoothHelper = BluetoothHelper(this, this)
            .setPermissionRequired(true)
            .create()  
  • You have some commitment to handle the lifecycle BluetoothHelper to work properly
   override fun onResume() {
        super.onResume()
        bluetoothHelper.registerBluetoothStateChanged()
   }
   override fun onPause() {
        super.onPause()
        bluetoothHelper.unregisterBluetoothStateChanged()
   } 
  • Turn Bluetooth on and off
   enable_disable.setOnClickListener {
            if (bluetoothHelper.isBluetoothEnabled()) bluetoothHelper.disableBluetooth()
            else bluetoothHelper.enableBluetooth()
   }
  • Instructions for locating devices
   start_stop.setOnClickListener {
            if (bluetoothHelper.isBluetoothScanning()) bluetoothHelper.stopDiscovery()
            else bluetoothHelper.startDiscovery()
   }
  • And finally, you can update the UI in the following methods using the BluetoothHelperListener interface.
   override fun onStartDiscovery() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
   }

   override fun onFinishDiscovery() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
   }

   override fun onEnabledBluetooth() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
   }

   override fun onDisabledBluetooh() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
   }

   override fun getBluetoothDeviceList(device: BluetoothDevice) {
        itemList.add(BluetoothDeviceModel(device.name, device.address))
        viewAdapter.notifyDataSetChanged()
   }

Licence

MIT License

Copyright (c) 2018 Tolga Bolatcan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
RxBle: Use Android Bluetooth API in Rx way
RxBle: Use Android Bluetooth API in Rx way

RxBle: Use Android Bluetooth API in Rx way A lightweight encapsulation of Android Bluetooth API. Use Android Bluetooth API in Rx way. Support multiple

Kotlin Asynchronous Bluetooth Low-Energy
Kotlin Asynchronous Bluetooth Low-Energy

Kable Kotlin Asynchronous Bluetooth Low Energy provides a simple Coroutines-powered API for interacting with Bluetooth Low Energy devices. Usage is de

A non-trivial Bluetooth LE app using Kable and app architecture best practices

kable_mvvm_demo The intention of this project is to demonstrate a non-trivial Bluetooth LE app using Kable and app architecture best practices. ⚠️ The

Open-source weight and body metrics tracker, with support for Bluetooth scales
Open-source weight and body metrics tracker, with support for Bluetooth scales

Open-source weight and body metrics tracker, with support for Bluetooth scales

Simple bluetooth flutter project

bluetooth_simple Simple bluetooth implementation. Getting Started This project is a starting point for a Flutter application. A few resources to get y

User-friendly Lightweight TPM Remote Attestation over Bluetooth

Ultrablue Ultrablue (User-friendly Lightweight TPM Remote Attestation over Bluetooth) is a solution to allow individual users to perform boot state at

A simple, lightweight library intended to take away some of the cruft and tediousness of using the Android BLE.

Blueteeth What Is Blueteeth? Blueteeth is a simple, lightweight library intended to take away some of the cruft and tediousness of using the Android B

Allows Android apps to interact with BLE beacons

Android Beacon Library An Android library providing APIs to interact with beacons. Please visit the project website for how to use this library. IMPOR

🍔 Meals is a small demo app based on modern Android technologies and MVVM architecture
🍔 Meals is a small demo app based on modern Android technologies and MVVM architecture

Meals 🍔 Meals is a small demo app based on modern Android technologies and MVVM architecture. built-in Kotlin, Coroutine, Flow, Retrofit, and Jetpack

Comments
  • I get the error:

    I get the error: "Receiver not registered"

    Related error is attached. error The temporary solution is to remove the "context.unregisterReceiver (mBluetoothDeviceFounderReceiver)" line in the onFinishDiscovering method in the BluetoothHelper class.

    opened by toxoz41 4
  • Bug: While the scanner is working, if the user turns off the bluetooth

    Bug: While the scanner is working, if the user turns off the bluetooth

    Test Device: Motorla dvice Android 5.0

    When startDiscovery, if rotate device and user off bluetooth when scanning

    Recive Error

    java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.DISCOVERY_FINISHED flg=0x10 } in c.tlgbltcn.library.BluetoothHelper$mBluetoothStateChangeReceiver$2$1@127ee31e at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:876) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) Caused by: java.lang.IllegalArgumentException: Receiver not registered: c.tlgbltcn.library.BluetoothHelper$mBluetoothDeviceFounderReceiver$2$1@d12e4db

    opened by webserveis 0
Releases(v1.7)
Owner
Tolga Bolatcan
Mobile Application Developer
Tolga Bolatcan
Kotlin Asynchronous Bluetooth Low Energy provides a simple Coroutines-powered API for interacting with Bluetooth Low Energy devices.

Kotlin Asynchronous Bluetooth Low Energy provides a simple Coroutines-powered API for interacting with Bluetooth Low Energy devices.

JUUL Labs 275 Sep 14, 2021
This library allows for easy access to a Bluetooth LE device's AdRecord and RSSI value. It offers additional functionality for iBeacons.

Bluetooth LE Library for Android This library allows for easy access to a Bluetooth LE device's Advertisement Records. It also offers: A simple runnin

Alexandros Schillings 843 Dec 13, 2022
BluePass extracts two factor authentication codes (2FA) from SMS and sends them to a paired device via Bluetooth RFCOMM.

BluePass extracts two factor authentication codes (2FA) from SMS and sends them to a paired device via Bluetooth RFCOMM.

Manuel Huber 15 Dec 4, 2022
The purpose is to share the Internet capability of one device to the entire Bluetooth LAN.

bluenet The purpose is to share the Internet capability of one device to the entire Bluetooth LAN. To make a prototype of a soft bus, or actually, I w

yunlong.wen 1 Jun 28, 2022
An Android Library for handling Bluetooth Low Energy on Android Easy

An Android Library for handling Bluetooth Low Energy on Android Easy

Leandro SQ 42 Jan 3, 2023
An Android library that solves a lot of Android's Bluetooth Low Energy problems

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.

Nordic Semiconductor 1.4k Jan 7, 2023
A reactive, interface-driven central role Bluetooth LE library for Android

RxCentralBle RxCentralBle provides a simple reactive paradigm for connecting to and communicating with Bluetooth LE peripherals from the central role.

Uber Open Source 198 Nov 29, 2022
A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Andrew Reed 220 Dec 28, 2022
BLESSED Coroutines, a Bluetooth Low Energy (BLE) library for Android using Kotlin Coroutines

BLESSED for Android with Coroutines - BLE made easy BLESSED is a very compact Bluetooth Low Energy (BLE) library for Android 8 and higher, that makes

Martijn van Welie 82 Jan 1, 2023
Smooth communication via bluetooth with other android devices or microcontrollers such as Arduino.

Android Smooth Bluetooth Smooth communication via bluetooth with other android devices or microcontrollers such as Arduino. Getting Started Add Gradle

Mantas Palaima 191 Nov 28, 2022