Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in BATTERY_PROPERTY_CAPACITY and BATTERY_PROPERTY_CHARGE_COUNTER #630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/src/main/java/com/termux/api/apis/BatteryStatusAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public static void onReceive(TermuxApiReceiver apiReceiver, final Context contex
public void writeJson(JsonWriter out) throws Exception {
Intent batteryStatus = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
final int batteryPercentage = (level * 100) / scale;

int health = batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1);
String batteryHealth;
switch (health) {
Expand Down Expand Up @@ -106,11 +102,12 @@ public void writeJson(JsonWriter out) throws Exception {

out.beginObject();
out.name("health").value(batteryHealth);
out.name("percentage").value(batteryPercentage);
out.name("percentage").value(batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY));
out.name("plugged").value(batteryPlugged);
out.name("status").value(batteryStatusString);
out.name("temperature").value(batteryTemperature);
out.name("current").value(batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW));
out.name("charge").value(batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER));
out.endObject();
}
});
Expand Down