Bluetooth State
Bluetooth State:
The Android Bluetooth State is the status of the balance of the device’s Bluetooth activity at the time that the statistic was taken.
It shows whether the Bluetooth is on or off and depending on the API of the device, it may also give more info about the Bluetooth connection, such as discovery of Bluetooth devices in the vicinity or if connected with a particular device.
Example:
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!-- activity_main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/bluetoothStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth Status"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#000000"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="6dp"/>
<Switch
android:id="@+id/bluetooth_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/bluetoothStatus"
android:layout_centerInParent="true"
android:text="Switch ON/OFF"
android:layout_marginTop="20dp"/>
</RelativeLayout>
</RelativeLayout>