Bluetooth’s technology is a high-speed, low-powered wireless technology link designed to connect devices such as phones or other portable equipment. It has a specification (IEEE 802.15.1) for low power radio communications to link computers, phones, and other network devices over a short distance in a wireless manner. Bluetooth signals cover distances, typically up to 10 meters or 30 feet. Bluetooth supports the waveband of 2.45 GHz and may support up to 721 kbps alongside three voice channels. This waveband has been put aside by international agreement to use Industrial, Scientific, and Medical devices (ISM).rd-compatible with 1.0 devices. Bluetooth is capable of connecting up to “eight devices” at a time. Every device offers a unique 48-bit address from the IEEE 802 standard. The Bluetooth specification defines and supports a variety of Bluetooth network connection. In this way, Bluetooth networking may be a remarkably flexible form of a wireless system for various short-range applications. Through this article, we want to share with you the implementation of an application that displays a list of Bluetooth Paired Devices along with their MAC IDs. A sample image is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.
Step by Step Implementation
To programmatically show a list of Bluetooth Paired devices against our device in Android, follow the following steps:
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Woking with the AndroidManifest.xml file
Go to the AndroidManifest.xml file and add these permissions required by the Bluetooth adapter: BLUETOOTH, BLUETOOTH_ADMIN, and ACCESS_COARSE_LOCATION.
Below is the complete code for the AndroidManifest.xml file.
Step 3: Working with the activity_main.xml file
Now go to the activity_main.xml file which represents the UI of the application. Create a Layout which will display the Paired list of Bluetooth devices along with their MAC Addresses, and a Button to fetch them. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.
Step 4: Working with the MainActivity.kt file
Go to the MainActivity.kt file, and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Output: Run on Physical Device
Note: Some data is masked to maintain privacy.
- How to Programmatically Enable/Disable Bluetooth in Android?
- How to Make Bluetooth Discoverable to Other Devices in Android?
- How to Display the List of Sensors Present in an Android Device Programmatically?
- How to programmatically hide Android soft keyboard
- Current Internet Connection Type in Real-Time Programmatically in Android
- How to Increase/Decrease Screen Brightness in Steps Programmatically in Android?
- How to Increase/Decrease Screen Brightness using Volume Keys Programmatically in Android?
- How to Detect Touch Event on Screen Programmatically in Android?
- How to Invoke Keyboard Programmatically in Android?
- How to Find the Screen Resolution of a Device Programmatically in Android?
- How to Obtain the Connection Information Programmatically in Android?
- How to Change the Screen Orientation Programmatically using a Button in Android?
- How to Programmatically Enable/Disable Wi-Fi in Android?
- How to Adjust the Volume of Android Phone Programmatically from the App?
- How to Control Lottie Animations Programmatically in Android?
- How to Check the Battery Level in Android Programmatically?
- How to Check if the Battery is Charging or Not in Android Programmatically?
- How to Check the Type of Charging (USB/AC) in Android Programmatically?
- How to Maximize/Minimize Screen Brightness Programmatically in Android?
- How to Listen for Volume Button and Back Key Events Programmatically in Android?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.