How to use bluetooth on Android

Russian Blogs

Recently, the project company needs to use appropriate content developed by Bluetooth, so I specifically checked the official Google documentation and did a second sorting, hoping to help friends who need to learn this part.

Introducing Bluetooth does not require me to be familiar with the people reading this article. Android provides a set of APIs to use Bluetooth, and the following operations can be performed:

  • Search for other Bluetooth devices
  • Hardware to request adapters
  • Set up an RFCOMM channel
  • Connect to other Bluetooth devices through discovery service
  • Data exchange
  • Managing multiple connections

Among them, this article only presents a simple technology for exchanging data between Bluetooth devices, refer to related documents for the rest. Also, this article only deals with the development of classic Bluetooth, not the development of Bluetooth Low Energy (BLE).

We have seen how, from our activity, we can associate a Bluetooth service (1) that performs and manages Bluetooth operations. In it, we can trigger a multicast event (2) which the Bluetooth receiver receives. Having received them, the bluetooth receiver, in turn, calls the interface function implemented (4) in our activity registered to the bluetooth receiver(3)

My advice. always follow the official guide and recommendations to write clean code.

The material is prepared by the Android Developer specialization.

Everyone is invited to a two-day online intensive, “Making a Mobile Mini-Game in 2 Days”. In 2 days you will make a mobile version of PopIt in Kotlin. The application will have a simple animation, clap sound, vibration, timer as a competition element. The intensive is suitable for those who want to try themselves as an Android developer. REGISTRATION

How to connect to another device with Bluetooth

Connecting and synchronizing devices is an important feature and purpose of Bluetooth connection. The whole process is meaningless if the person doesn’t know how to connect this or that device.

In order to connect, it is mandatory for the user to have the function activated and then the following algorithm must be followed:

  • You need to go into the settings in the section with the same name;
  • Next, the user should activate the function and also enable visibility so that other devices can see the phone;
  • A list of those devices that the user can set up a connection to will now appear. If it is empty, it is worth clicking on the item “Search for devices”;
  • After this, the user should click on the device to which he wanted to connect;
  • Create a pairing request and wait for the other person to confirm the connection request;
  • When synchronization has occurred, the connected device will automatically go to the “Connected” section.

In this way you can simply and easily connect to another phone. The process is simple, so it is worth to know every owner of the phone on any system.

For more details on how to connect this or that device, the user can watch this video

How to know the version of Bluetooth on your phone?

Usually users are interested not so much in the address of the wireless module, but in its version, as this parameter affects the support of various accessories and communication characteristics. There are several ways to see the version of Bluetooth on Android: through store sites, from technical documentation or with the help of programs.

How to check the Bluetooth version on Android :

An alternative method of finding out what version of Bluetooth your smartphone is is to use other apps. They don’t show exact data in this regard, but they give hints. For example, if DevCheck Hardware or System Info shows Bluetooth LE firmware support, then the smartphone has version 4 or higher installed on it. This is already enough to work with most modern devices at high speed.

See also  How to check your balance on your computer

Under Android Version, you see the currently installed version.

Open the device menu and select Settings.

Select About Device or Phone Info.

Select Software info. If there is no such item, go to the next step.

Your Android Version shows the currently installed version.

To use the instructions on the Samsung website, the first digit is enough, e.g. in the screenshot below, version 8 is installed.

Was released in 2009 and for the first time used high-speed (HS) broadcasting. Speed increased to 24Mbps. It was realized by installing two modules (Bluetooth2.1EDR and 802 protocol module.11). It is the second module and “gives” a speed bump, but does not give Wi-Fi compatibility. Files of small size are transferred with the module 2.1EDR, bulk. via 802.11. The drawback of this solution was the increased power consumption.

These updates introduced support for unencrypted channels, incoming signal strength display, and accelerated device detection/connection. Also, interference immunity was improved, transmission speed was increased (721Kbit/s) and network anonymity was implemented. These versions allowed to transmit voice messages and stereo sound (A2DP profile). Currently, you can buy a cheap phone from a Chinese manufacturer with an upgrade to 1.2.

Power consumption in version 2.1 dropped by a factor of almost 10, there is additional bandwidth, making it easier to use multiple connections at once. Implement a one-button connection.

Now you know why an error can occur when a Bluetooth device cannot be found, and how to fix this problem.

Bluetooth capabilities on Android

The first thing we think of most when it comes to “Bluetooth” technology is file transfer. experienced users use it to connect a headset, headphones, mouse, keyboard. With this technology, the device can:

  • Create an Internet access point for other devices;
  • connect to a printer and print the necessary material;
  • Use your smartphone as a peripheral device for your PC;
  • connect to your computer and even control it.

Of course, everything depends on the model of phone and gadget with Bluetooth receiver.

All wireless modules have unique identifiers that help devices differentiate themselves from each other. Bluetooth, along with Wi-Fi, also has its own special address. It is issued to all smartphones, including Xiaomi, Honor, Meizu, Samsung. Knowing this value, the user is able to fine-tune the work of the adapter and related functions. Next, let’s figure out how to find out the Bluetooth address of Android and talk about ways to fix when the identifier is unavailable.

How to disable one or more devices

Bluetooth technology allows you to establish a wireless connection between two smartphones. File transfer will become available after the pairing process is passed. Despite the many advantages of the development, it has some disadvantages in the form of restrictions on the number of connected devices. There are several ways to remove Bluetooth devices from the phone. The first method will suit those who want to clear data on only one unnecessary component. You need to perform the following actions:

This method is not practical if you need to remove a lot of paired Bluetooth devices. How to clear the list of all the devices saved by the Android operating system, the following method will tell you:

  • The main menu also opens first.
  • After this you will go to the settings section.
  • Here you will need to find the item with the name “Applications”.
  • At the top will be displayed the command “All”, you need to tap it.
  • In the list displayed will be the application “Bluetooth”, it must be selected by the user.
  • A window opens in which you must find the “Clear cache memory” command.
  • After deleting the data the list of paired devices will become empty.
See also  Transferring data from Samsung to Huawei

In some cases user could accidentally delete the desired Bluetooth device. There is no need to panic because there are methods which can be used to find out how to restore them. The easiest solution is to perform a reboot of the smartphone. With the help of this action the user can correct minor system failures, which can lead to cache storage clogging. Рестарт системы нередко помогает исправить функции, которые перестали корректно функционировать.

I just knowed Android bluetooth device name is cached in the phone. (when phone find the bluetooth device)

I want to clear the blueooth cache. I’m making application about bluetooth.

I just knowed Android bluetooth device name is cached in the phone. (when phone find the bluetooth device)

I can’t find solution anywhere. I just saw fetchUuidsWithSdp. someone said it clears the bluetooth cache in Android phone.

but I don’t know how use this method and I don’t think that fetchUuidsWithSdp will clear the cache.

Please Let me know how to clear the bluetooth cache in Android or how to use fetchUuidsWithSdp.

Как включить Bluetooth

Как работает Bluetooth, мы выяснили. Что он умеет делать – тоже. Но как включить его на своем устройстве? To begin with, as an example, let’s consider a smartphone, because absolutely all such gadgets are equipped with “blue-zub”.

To activate the communication protocol, just open the notification panel and tap the Bluetooth icon. After that, it should light up, which is an indication that the function is properly enabled.

It is not necessary to keep Bluetooth turned on all the time. It greatly affects the battery, draining it.

You can also activate Bluetooth through your smartphone’s settings by opening the appropriate section. The user only needs to move the slider to the right, and then the sensor will work.

On a computer and a TV with Smart TV the operation is done in a similar way. Unless you have a notification panel with a Bluetooth icon on these devices. But you can activate it through the settings. If your device does not have a sensor, you will need to buy an adapter in an electronics store.

On devices like wireless speakers, you activate Bluetooth by pressing the icon button. And with smart watches or wireless headphones, in most cases it is not even necessary to do this. The sensor there works in constant mode.

Bluetooth technology capabilities on Android

Bluetooth technology appeared on the market in 1998 and immediately gained popularity among the developers of multi-functional gadgets. This method of transmitting information is a new alternative to the infrared ports that were used before. The reason for the popularity of Bluetooth technology is the transmission speed.

The first examples of Bluetooth modules transferred files at speeds of up to 721 kb/s, modern ones. in large portions up to 24 MB/s.

No Internet traffic is used to pair devices via Bluetooth, you just need two devices with functioning modules.

With the advent and development of Wi-Fi the popularity of Bluetooth technology has not decreased because it uses significantly less power resources. For this reason, wireless headphones, sports bracelets, smart watches and other Bluetooth devices are created.

Use a configuration file

Starting with Android 3.0, the Bluetooth API supports the use of Bluetooth profiles. The Bluetooth configuration file is a wireless interface specification that is suitable for Bluetooth communication between devices. An example is the hands-free configuration file. For phones connected to wireless headsets, both devices must support hands-free profiles.

You can implement BluetoothProfile interface to support specific Bluetooth profiles by writing your own class. Android Bluetooth API provides implementation of the following Bluetooth configuration files:

  • Headphones. The headset profile provides Bluetooth headset support for use with cell phones. Android provides a BluetoothHeadset class, which is an agent used to manage Bluetooth headset services through inter-process communication (IPC). This includes Bluetooth headsets and hands-free profiles (version 1.5). The BluetoothHeadset class contains support for AT commands. For a detailed discussion of this topic, please refer to the manufacturer-specific AT commands.
  • A2DP. Advanced Audio Distribution Profile (A2DP) defines a way to transmit high quality audio from one device to another via Bluetooth connection and streaming. Android provides a BluetoothA2dp class, which is a proxy for controlling the A2DP Bluetooth service via IPC.
  • Medical Devices. In Android 4.0 (API level 14) support for Bluetooth Health Device Profile (HDP) is now available. This allows you to create applications that use Bluetooth to communicate with Bluetooth-enabled devices such as heart rate monitors, glucose meters, thermometers, scales, etc. Д. For a list of supported devices and their corresponding specialization codes for these devices, see. In the assigned Bluetooth number at Note that these values are also referred to as MDC_DEV_SPEC_PROFILE_ in the “Appendix to Naming Rules” of the ISO / IEEE 11073-20601 specification [7]. For a detailed discussion of HDP, see. In a workability device configuration file.
See also  Sony speaker does not see bluetooth

The following are basic steps for using configuration files:

  • Get the default adapter (see. Bluetooth Setup).
  • Use getProfileProxy. To establish a connection to the profile proxy object associated with the profile. In the following example, the proxy profile object is an instance of BluetoothHeadset.
  • Configure BluetoothProfile.ServiceListener. This listener sends a notification to the BluetoothProfile IPC client when it connects to or disconnects from the service.
  • In onServiceConnected get the descriptor of the proxy profile object.
  • After getting a profile proxy you can immediately use it to monitor the connection status and perform other operations related to the profile.

For example, the following code snippet shows how to connect to the BluetoothHeadset proxy object to be able to control the headset profile:

Special Provider AT Commands

Starting with Android 3.0, applications can register to receive system broadcasts of predefined specific AT commands sent by the headset (e.g., Plantronics XEVENT commands). For example, the app can receive a broadcast indicating the battery level of the connected device and notify the user or take other actions as needed. Create a broadcast receiver for ACTION_VENDOR_SPECIFIC_HEADSET_EVENT, designed to handle vendor-specific AT commands from the headset.

Health Device Profile

In Android 4.0 (API level 14) support for Bluetooth Health Device Profile (HDP) appeared. This allows to create applications using Bluetooth to communicate with Bluetooth-enabled devices such as heart rate monitors, glucose meters, thermometers, scales, etc. Д. The Bluetooth Health API includes the BluetoothHealth, BluetoothHealthCallback, and BluetoothHealthAppConfiguration classes, which are introduced in.

When using the Bluetooth Health API, it’s helpful to understand the following key HDP concepts:

Creating HDP applications

Below are the basic steps for creating an Android HDP app:

  • Get link to BluetoothHealth proxy object. Similar to regular A2DP profile headsets and devices, you must use BluetoothProfile types.ServiceListener and HEALTH for getProfileProxy call. To establish a connection to a proxy profile object.
  • Create a BluetoothHealthCallback and register the application configuration (BluetoothHealthAppConfiguration), which acts as a health aggregation device.
  • Establish a connection with the medical device. Some devices initiate the connection. For such devices this step is not necessary.
  • After successfully connecting to the serviceability device, use the file descriptor to perform read/write operations on the serviceability device. The data obtained must be interpreted with the help of the Health Manager, which implements the IEEE 11073-xxxxx specification.
  • When finished, close the uptime channel and unregister the application. The channel will also be closed if it is not used for a long time.

For a complete code example describing the above steps, see. Under Bluetooth HDP (Device Performance Profile).

Denial of responsibility | Contacts |RSS | SE | EN | BR | DE