Example usage for android.os BatteryManager BATTERY_HEALTH_COLD

List of usage examples for android.os BatteryManager BATTERY_HEALTH_COLD

Introduction

In this page you can find the example usage for android.os BatteryManager BATTERY_HEALTH_COLD.

Prototype

int BATTERY_HEALTH_COLD

To view the source code for android.os BatteryManager BATTERY_HEALTH_COLD.

Click Source Link

Usage

From source file:org.wso2.emm.agent.api.DeviceState.java

/**
 * Conversion from health condition int to String can be done through this method.
 *
 * @param health integer representing the health condition.
 * @return String representing the health condition.
 *//*from w ww  .  j av  a2s  .  com*/
private String getHealth(int health) {
    String healthString = UNKNOWN;
    switch (health) {
    case BatteryManager.BATTERY_HEALTH_COLD:
        healthString = COLD;
        break;
    case BatteryManager.BATTERY_HEALTH_DEAD:
        healthString = DEAD;
        break;
    case BatteryManager.BATTERY_HEALTH_GOOD:
        healthString = GOOD_CONDITION;
        break;
    case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
        healthString = OVER_VOLTAGE;
        break;
    case BatteryManager.BATTERY_HEALTH_OVERHEAT:
        healthString = OVER_HEAT;
        break;
    case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
        healthString = FAILURE;
        break;
    }
    return healthString;
}

From source file:saphion.services.ForegroundService.java

public int readbattery() {
    Intent batteryIntent = getApplicationContext().registerReceiver(null,
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    int rawlevel = batteryIntent.getIntExtra("level", -1);
    double scale = batteryIntent.getIntExtra("scale", -1);
    int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    isconnected = (plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB
            || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS);
    level = -1;/*w w w.j av  a 2  s . co  m*/
    if (rawlevel >= 0 && scale > 0) {
        level = (int) ((rawlevel * 100) / scale);
        Log.d("rawLevel: " + rawlevel);
        Log.d("scale: " + scale);
    }

    temperature = Functions.updateTemperature(
            (float) ((float) (batteryIntent.getIntExtra("temperature", 0)) / 10),
            mPref.getBoolean(PreferenceHelper.MAIN_TEMP, true), true);

    int inthealth = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
    health = "";
    switch (inthealth) {
    case BatteryManager.BATTERY_HEALTH_COLD:
        health = "Cold";
        break;
    case BatteryManager.BATTERY_HEALTH_DEAD:
        health = "Dead";
        break;
    case BatteryManager.BATTERY_HEALTH_GOOD:
        health = "Good";
        break;
    case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
        health = "Over Voltage";
        break;
    case BatteryManager.BATTERY_HEALTH_OVERHEAT:
        health = "Overheat";
        break;
    case BatteryManager.BATTERY_HEALTH_UNKNOWN:
        health = "Unknown";
        break;
    case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
        health = "Unspecified failure";
        break;
    }

    if (mPref.getBoolean(PreferenceHelper.KEY_ONE_PERCENT_HACK, false)) {
        try {
            java.io.FileReader fReader = new java.io.FileReader(
                    "/sys/class/power_supply/battery/charge_counter");
            java.io.BufferedReader bReader = new java.io.BufferedReader(fReader);
            int charge_counter = Integer.valueOf(bReader.readLine());
            bReader.close();

            if (charge_counter > PreferenceHelper.CHARGE_COUNTER_LEGIT_MAX) {
                disableOnePercentHack("charge_counter is too big to be actual charge");
            } else {
                if (charge_counter > 100)
                    charge_counter = 100;

                level = charge_counter;
            }
        } catch (java.io.FileNotFoundException e) {
            /*
             * These error messages are only really useful to me and might
             * as well be left hardwired here in English.
             */
            disableOnePercentHack("charge_counter file doesn't exist");
        } catch (java.io.IOException e) {
            disableOnePercentHack("Error reading charge_counter file");
        }
    }

    return level;
}