javaandroidunits-of-measurementbatterylevel

Unit of Measure for Battery Level Percentage


I'm using JSR 363 Reference Implementation in a project. I wish to use and display the Battery Level obtained from a Device.

Which Quantity could be used to represent battery level as a percentage. Although ElectricPotential is the obvious candidate, the devices I'm targeting report the value in a relative range from empty to full. See iOS docs for example.

I plan to display it as a percentage, ideally using the QuantityFormat in the general manner of handling other Quantities.

Battery Level: 57%

The alternate display is likely graphical which I wouldn't expect the library to provide:

battery levels
(source: freeiconbox.com)


Solution

  • While Java ME 8 Embedded offers an optional package for power management, depending on your target devices, they may not run MEEP 8 or Java ME 8 Embedded. Fortunately, JSR 363 supports both, and we'll provide something similar on top of MEEP 8 and our Ri, too.

    The actual class will change a bit since we're restructuring the quantities coming with the API and those in additional modules, but currently in the SI class of the RI, a Dimensionless unit constant PERCENT

    /**
     * A dimensionless unit accepted for use with SI units (standard name <code>%</code>).
     */
    public static final Unit<Dimensionless> PERCENT
    

    is going to be available and the best unit for this use case.

    Regards, Werner Keil Co-Spec Lead, JSR 363