{"id":317,"date":"2023-05-17T15:27:14","date_gmt":"2023-05-17T15:27:14","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=317"},"modified":"2023-05-17T15:27:15","modified_gmt":"2023-05-17T15:27:15","slug":"bluetooth","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/17\/bluetooth\/","title":{"rendered":"Bluetooth"},"content":{"rendered":"\n<p>Bluetooth is a way to send or receive data between two different devices. Android platform includes support for the Bluetooth framework that allows a device to wirelessly exchange data with other Bluetooth devices.<\/p>\n\n\n\n<p>Android provides Bluetooth API to perform these different operations.<\/p>\n\n\n\n<ul>\n<li>Scan for other Bluetooth devices<\/li>\n\n\n\n<li>Get a list of paired devices<\/li>\n\n\n\n<li>Connect to other devices through service discovery<\/li>\n<\/ul>\n\n\n\n<p>Android provides BluetoothAdapter class to communicate with Bluetooth. Create an object of this calling by calling the static method getDefaultAdapter(). Its syntax is given below.<\/p>\n\n\n\n<p>private BluetoothAdapter BA;<\/p>\n\n\n\n<p><strong>BA = BluetoothAdapter.getDefaultAdapter();<\/strong><\/p>\n\n\n\n<p>In order to enable the Bluetooth of your device, call the intent with the following Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is.<\/p>\n\n\n\n<p>Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);<\/p>\n\n\n\n<p>startActivityForResult(turnOn, 0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Sr.No<\/td><td>Constant &amp; description<\/td><\/tr><tr><td>1<\/td><td>ACTION_REQUEST_DISCOVERABLEThis constant is used for turn on discovering of bluetooth<\/td><\/tr><tr><td>2<\/td><td>ACTION_STATE_CHANGEDThis constant will notify that Bluetooth state has been changed<\/td><\/tr><tr><td>3<\/td><td>ACTION_FOUNDThis constant is used for receiving information about each device that is discovered<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Once you enable the Bluetooth , you can get a list of paired devices by calling getBondedDevices() method. It returns a set of bluetooth devices. Its syntax is.<\/p>\n\n\n\n<p>private Set&lt;BluetoothDevice&gt;pairedDevices;<\/p>\n\n\n\n<p>pairedDevices = BA.getBondedDevices();<\/p>\n\n\n\n<p>Apart from the parried Devices , there are other methods in the API that give more control over Bluetooth. They are listed below.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Sr.No<\/td><td>Method &amp; description<\/td><\/tr><tr><td>1<\/td><td>enable()This method enables the adapter if not enabled<\/td><\/tr><tr><td>2<\/td><td>isEnabled()This method returns true if adapter is enabled<\/td><\/tr><tr><td>3<\/td><td>disable()This method disables the adapter<\/td><\/tr><tr><td>4<\/td><td>getName()This method returns the name of the Bluetooth adapter<\/td><\/tr><tr><td>5<\/td><td>setName(String name)This method changes the Bluetooth name<\/td><\/tr><tr><td>6<\/td><td>getState()This method returns the current state of the Bluetooth Adapter.<\/td><\/tr><tr><td>7<\/td><td>startDiscovery()This method starts the discovery process of the Bluetooth for 120 seconds.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Bluetooth is a way to send or receive data between two different devices. Android platform&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/317"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":318,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/317\/revisions\/318"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}