Blutooth API Basic Data Transfer

How To Use Android Bluetooth API For Basic Data Transfer From One Device To Another Device

Introduction:

Bluetooth:

The Android platform supports Bluetooth connection, which allows us to exchange data with other Bluetooth devices. The application framework provides Bluetooth related functionality through the Android Bluetooth APIs.All of the Bluetooth APIs are available in the Android Bluetooth package.

There are two types of Bluetooth in Android Classic Bluetooth and Bluetooth devices with low power requirements. Android 4.3 (API level 18) introduces API support for Bluetooth Low EnergyBluetooth(BLE).

Here we will only focus on Classic Bluetooth. Classic Bluetooth is the right choice for more battery-intensive operations, which include streaming and communicating between Android devices.

Steps to use Bluetooth in Android

Step 1:

Bluetooth permissions –

Note:

1- If your app targets Android 9 (API level 28) or lower, you can declare the        ACCESS_COARSE_LOCATION permission instead of the ACCESS_FINE_LOCATION permission.
2- ACCESS_FINE_LOCATION or ACCESS_FINE_LOCATION comes under the dangerous permissions so we need to define the runtime permission for these.

Step 2:

Set up Bluetooth and Scan for Available devices:-

Now let’s build our layout file. So open activity_bluetooth_device_list file and add the below code.

Step 3:

Now in the BluetoothDeviceListActivity, add these below code:

Step 4:

Now add these code in class BluetoothConnectionService

Step 5:

Now add these code in DeviceListAdapter for listing Bluetooth devices

Step 6:

Now add these code  in  device_adapter_view layout

Now on running this code, we can see our application will scan for available Bluetooth devices and we see the list of devices and can pair and connect with them for basic data communication(like sending text messages).

You can also read our blogs on Android:

1: Android Navigation Component – Android Jetpack

2: Offline Content Storage and Sync with Server when Modified

3: Custom Camera using SurfaceView

4: Capture Image on Eye Blink

5: How to Use Data Binding in Android

InnovationM is a globally renowned Android app development company in India that caters to a strong & secure Android app development, iOS app development, hybrid app development services. Our commitment & engagement towards our target gives us brighter in the world of technology and has led us to establish success stories consecutively which makes us the best iOS app development company in India. We are also rated as the best Mobile app development company in India.

Thanks for giving your valuable time. Keep reading and keep learning 🙂

Leave a Reply