<p>Earlier this year I ran into an interesting article about a method to locate smartphones based only on the power consumption of the device, called <a href="http://arxiv.org/abs/1502.03182" rel="nofollow">PowerSpy</a>.</p>

<p>While I have never implemented/tested the method myself, the authors claim that:</p>

<blockquote>
  <p>On Android reading the phone’s aggregate power meter is done by repeatedly reading the following two files: <br/>
  <code>/sys/class/power_supply/battery/voltage_now</code> <br/> <code>/sys/class/power_supply/battery/current_now</code>.</p>
</blockquote>

<p>They also claim to have tested the method on Nexus 4, Nexus 5 and HTC. While this is not that specific about which exact versions of Android the devices were equipped with, Nexus 4 is supposed to come with API level 17 and Nexus 5 with API level 19, but both phones seem to be subject to OS upgrades. </p>

<p>However, this seems to be a radically different method when compared with the ones mentioned by the other posters, so probably worth mentioning. Unfortunately, it seems to be a low-level approach, so a lot of work might be required to get what you need, since power, as in Physics, does not really mean battery consumption. But maybe you need it this way.</p>

<p>Last, the article mentioned that access to the two files requires no special permissions (which kind of motivated the study they did in the first place).</p>

<p><strong>EDIT</strong></p>

<p>Second thought, if you plot <code>P=U*I</code> (getting U and I as mentioned above) and integrate over time (that would be a sum in this discrete case) you might just get a very good approximation of battery consumption. Maybe you also factor in a Kalman filter (to attenuate the noise on U and I, keeping in mind that your algorithms are not the only consumer) and you might just get what you want.</p>
Android BatteryManager Alternatives
<p>I'm trying to get battery stats in my application for some benchmarking. The wonderful BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER lets me query the device's micro-amps which is great. However, this was only introduced in API 21 so the number of devices this can reach is quite limited. Is there a compatible way to do something similar in lower versions of the APIs (down to 4.0)? I know BatteryManager.EXTRA_LEVEL will give me the percentage but that's really not fine-grained.</p>