Android Service for BLE

The BLE functionality is enabled through an Android Service by the app so that the BLE can be active in the background to perform operations such as, maintaining an existing connection, and continue performing access operations when the app is not in the foreground. BLEService class in BLEService.java file in the MCHPTransparentUART Android app example provides the BLE service with methods and callbacks.

An Android Service is an application component that can perform long-running operations in the background, and doesn't provide a user interface. Another application component can start a service, and can continue to run in the background even if the user switches to another application. Additional information on Services can be found here.

The Android service must be declared in the Android manifest as one of the application components.

App manifest AndroidManifest.xml in the MCHPTransparentUART Android app example declares the BLE service. The BLE service declared in the AndroidManifest.xml is highlighted in the below screenshot.

service.png

The PeripheralControlActivity activity uses BLEService for all the BLE operations. The PeripheralControlActivity being the client of the BLEService binds to the service by calling the bindService() method in the onStart() method at the start of the activity. The bindService() call with the BLEService connects to the BLEService application service, creating the service if needed.

bind.png

The PeripheralControlActivity can disconnect from the BLEService by calling the unbindService() with the BLEService connection handle.

unbind.png

It should be noted that bindService() and unbindService() should be called in matching Android activity state callbacks at the beginning (e.g. onStart()) and ending (e.g. onStop()).

© 2019 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.