Search code examples
androidbluetoothibeacon-android

How to check battery consumption caused by Bluetooth Scans


I have an Android application to detect Eddystone beacons using the Android Beacon Library. I would like to test the battery consumption caused by the application to find the optimal background and foreground scan rates. In Settings > Apps > MyBeaconDetectorApp, it shows 0% battery usage after having the bluetooth On for more than an hour. I think the application is in background and hence it is 0%. However, how do I check the battery consumption caused by Bluetooth scans. I have set my BackgroundBetweenScanPeriod as 1 minute.

Thanks


Solution

  • While it is difficult to measure the battery consumption directly, here is the technique I use:

    1. Use a test device with a limited number of apps installed that will be running in the background. A stock Nexus device after factory reset is ideal.

    2. Charge the battery to 100%

    3. Put the device into airplane mode and put bluetooth on.

    4. Install your app start it running in the background. Turn off the screen, and disconnect the device's USB connector.

    5. Note the start time.

    6. Let the app run in the background for at least 8 hours, ideally in the presence of at least one beacon.

    7. Measure the battery level. The delta from 100% is the percentage drain. Note this number and the end time.

    8. Look up how many mAH your battery has for your phone model. Multiply the percentage drain by the mAH and divide by the time of the test in hours. This tells you how many mA the phone uses when running your app.

    Next, uninstall your app, and repeat the procedure above. This will give you a baseline battery drain for your device without your app running.

    Finally, subtract the mAH baseline from the mAH with your app running to measure the additional mAH used by your app.

    One final note: if you are really scanning every minute in the background (the default is every five minutes to save battery), I would expect this may cause a significant additional battery drain. Testing using the procedure above will tell you for sure. I'd love to hear your results!