TUTORIALS: How to Develop Simple Bluetooth Android Application

image source droidxpert.com

By: Hansvin Tandi Sugata

The wireless-networking standard technology called bluetooth has quite become a common way to replace the wires on short distances. The term of Bluetooth was invented by Erricson in 1994. Bluetooth uses radio waves in the ISM band from 2.4 to 2.485 GHz (same as WIFI, but using a different technology). With a gadget such as a smartphone or tablet, a Bluetooth connection is the easiest way to send and receive data.

Some of you might ever think how to make a remotely controled device. An Android device has Java support, built-in Bluetooth module and a large variety of sensors. With an open architecture and a large community, Android allows anyone to build applications with simple tools and resources. In other words, anyone can build an applications for a smartphone or tablet with Android tools.

By using the buit-in Bluetooth module, we can actually do:

  1. Checking whether our device support bluetooth or not.
  2. Finding device in the nearby area and then pair it.
  3. Opening a RFCOMM (Radio Freqency Communication) channel, in such a way to send and recieve data.

This tutorials will teach you the basic of how to build an Android app using the an Android Studio development environment. Therefore, we need to install Android Studio as an Android application maker before we start to make an app. You can get Android Studio freely from this source ( http://developer.android.com/sdk/index.html ).


1. Ask for Bluetooth Permission.

Create a new project. Then, on the AndroidManifest.xml we put this code:


<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />


android.permission.BLUETOOTH means that we ask a permission to access the android Bluetooth, whereas android.permission.BLUETOOTH_ADMIN means that we ask a permission to find others nearby bluetooth so we can pair with it.

2. Make a command to turn on the Bluetooth

On this step, we will make a command to turn on the Bluetooth if the Bluetooth is off. The code bellow should be put on src/MainActivity.java

public static final int REQUEST_ENABLE_BT=999;
protected void onCreate(Bundle savedInstanceState)

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled())

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);



protected void onActivityResult(int requestCode, int resultCode, Intent data)

if (requestCode == REQUEST_ENABLE_BT)

String message;
if (resultCode == RESULT_OK)

message = "Bluetooth is on";

} else {

message = "Bluetooth is off";

Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);



3. Add an ArrayList to save the data and also to save the adapter.

private ArrayList<String> items = new ArrayList<>();
ArrayAdapter adapter;
private ArrayList<BluetoothDevice> arrayPairedDevices = new ArrayList<>();

About the author: Admin