As you might be aware, Bluetooth technology has been one of the most used technology when a connection has to be established with a remote device. But this technology also has a major limitation, i. Therefore an improved version of this technology with low energy consumption was introduced, called BLE. Therefore also on was introduced with API 18 Android 4. This opened up a whole new dimension in the world of Android development. All sorts of new hardware devices were introduced in the market, with compliance to Bluetooth low energy standard, like heart rate monitors, fitness devices and many more. Since this Android Bluetooth low energy API is a little new. Till now there is no proper code example available for its implementation. Therefore here in this tutorial, I will show you how to make an Android Bluetooth Low Energy Example, with latest APIs. Since BLE is still new to Android, some improvements were made in API 21 for the same, where the way to detect low energy Bluetooth devices was changed. This lead to deprecation of some old APIs. Primarily scanning for available Bluetooth LE devices using, mBluetoothAdapter. The new API suggests to use startScan method of BluetoothLeScanner class, which can be initialized from the same BluetoothAdapter class. But the problem which many of you must have faced, is these new API methods do not work on old APIs, as they are not backward compatible. Hence here we will make an Android Bluetooth Low Energy example, with backward support till API 18. The above example shows the best practices to detect a BLE device in an Android app with support up to API 18. I have randomly selected a Generic attribute Gatt profile above to print its BluetoothGattCharacteristic object using gatt. To actually read BLE attributes, you may need to write code specifically for your application as there may not be a single way to do it, as there are around 50 Gatt based profile specifications. Hence lets understand each component of Android Bluetooth Low Energy API individually. Working of Bluetooth LE in Android As I mentioned BLE has different Gatt profiles, each BLE device has a profile, through which they can act as a server. Here in the example above, mobile app would act as a client and the BLE device would act as a server. Scanning Bluetooth Low Energy Devices In the above example I scanned BLE devices using the highest power consumption mode ScanSettings. As here my objective was to detect nearby BLE devices immediately. But in total, the new API offers three modes in which nearby BLE devices could be scanned. Good for use when BLE device detection needs to be done in background. Also detects the BLE devices fastest, hence should be used when the app is in foreground. Reading BLE Characteristics in Android BLE characteristic is the actual data which is served through the BLE device. For example heart rate from a heart rate BLE device is a characteristic. Reading BLE characteristics or getting notified of changed BLE characteristics could be a whole different tutorial. As this could have a huge amount of customizations. Therefore here lets lets discuss the basic part only to get you started. To read Bluetooth low energy characteristics after scanning, we first need to connect to a BLE device using connectToDevice method as shown above. Then further a connection needs to be established with a Gatt profile using device. Further when a connection is established we need to discover all the services using gatt. This would invoke onServicesDiscovered method, where you can select a service and determine the types of characteristics it has. If the characteristic type is read, then the gatt. But if characteristic type is notify, you may need to set notifications using the setCharacteristicNotification method. More of this could be read from , as reading Bluetooth Low Energy characteristic notifications is not in our scope. Hope this Android Bluetooth Low Energy example helped you in getting started and scanning your first BLE device. Connect with us on Facebook, Google+ and Twitter for more updates. This causes some devices to immediately reject the attempt to connect. Do you know of a way to turn that off? Also, I am confused about what the API actually does when connectGatt connectGatt this, false, gattCallback ; is called with the option set to true rather than false. There appears to be an element of truth to that but it is very unreliable. So it is not clear to me how that feature is related to gattClose. When should I call it and when should I not call it? It appears if I call gattClose after a disconnect the autoconnect will NEVER work. I am guessing I might have to re-do connections from the start and re-discover everything. I am having a lot of troubles getting consistent behavior of connections when more than one device is paired and I try and connect and or reconnect to these devices. In many cases the call to connect simply does not cause any response at all. Logcat sits there and shows nothing. If you have any better understanding of what connectGatt does and what gattClose does, I would greatly appreciate it!!! Thanks, Brian PS: Great explanations on what you have displayed so far. I will need to make my apps compatible with 5. ScanLeDevice is called twice: once with the enable argument set to true telling it to start scanning , and then again with enable set to false telling it to stop scanning. The problem is in the if-else clause. So even if your device connects before postDelayed timer is done, stopScan will get called when the timer runs out. My OOP is pretty weak, but I think that the scan is stopping fine. My solution was to comment out the second mLEScanner. That would be line 131 on this page, which is inside the else part of the outer if-else clause. You can also probably remove the call to scanLeDevice that is inside the connectToDevice method. That essentially does the same thing. This code has been very helpful though. I want to send a string or a command to my blue sensor device from the mobile app. Currently my app is able to scan the devices, connect to the devices and read the data that is sent from the sensor. Now i want to send a command to the sensor from the app. Please guide me how to do that. I dig more into API documentation on Android Developers website and came to know that for API level above 21, you can set Scan settings with different interval and scan window. Can you please tell me what is the interval and window for scanning in API level below 21.