Android Bluetooth TutorialBluetooth is a way to exchange data with other devices wirelessly. Android provides Bluetooth API to perform several tasks such as:
Android Bluetooth APIThe android.bluetooth package provides a lot of interfaces classes to work with bluetooth such as:
android-preferences-example BluetoothAdapter classBy the help of BluetoothAdapter class, we can perform fundamental tasks such as initiate device discovery, query a list of paired (bonded) devices, create a BluetoothServerSocket instance to listen for connection requests etc. Constants of BluetoothAdapter classBluetoothAdapter class provides many constants. Some of them are as follows:
Methods of BluetoothAdapter classCommonly used methods of BluetoothAdapter class are as follows:
Android Bluetooth Example: enable, disable and make discovrable bluetooth programmaticallyYou need to write few lines of code only, to enable or disable the bluetooth. activity_main.xmlDrag one textview and three buttons from the pallete, now the activity_main.xml file will like this: File: activity_main.xml Provide PermissionYou need to provide following permissions in AndroidManifest.xml file. The full code of AndroidManifest.xml file is given below. File: AndroidManifest.xml Activity classLet's write the code to enable, disable and make bluetooth discoverable. File: MainActivity.java You need to run it on the real device (e.g. mobile) to test the application.Next topics of android bluetooth tutorial:android bluetooth list paired devices example |