Example usage for android.os BatteryManager EXTRA_TEMPERATURE

List of usage examples for android.os BatteryManager EXTRA_TEMPERATURE

Introduction

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

Prototype

String EXTRA_TEMPERATURE

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

Click Source Link

Document

Extra for android.content.Intent#ACTION_BATTERY_CHANGED : integer containing the current battery temperature.

Usage

From source file:org.protocoderrunner.apprunner.api.PDevice.java

@ProtoMethod(description = "", example = "")
@ProtoMethodParam(params = { "" })
public void battery(final StartBateryListenerCB cb) {
    WhatIsRunning.getInstance().add(this);
    batteryReceiver = new BroadcastReceiver() {
        int scale = -1;
        int level = -1;
        int voltage = -1;
        int temp = -1;
        boolean isConnected = false;
        private int status;
        private final boolean alreadyKilled = false;

        @Override/*from   www .jav a 2  s .  co m*/
        public void onReceive(Context context, Intent intent) {
            level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
            voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
            // isCharging =
            // intent.getBooleanExtra(BatteryManager.EXTRA_PLUGGED, false);
            // status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
            status = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

            if (status == BatteryManager.BATTERY_PLUGGED_AC) {
                isConnected = true;
            } else if (status == BatteryManager.BATTERY_PLUGGED_USB) {
                isConnected = true;
            } else {
                isConnected = false;
            }

            BatteryReturn o = new BatteryReturn();

            o.level = level;
            o.temperature = temp;
            o.connected = isConnected;

            // plugConnected = isConnected;
            cb.event(o);
            Log.d("BATTERY", "level is " + level + " is connected " + isConnected);
        }
    };

    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    getContext().registerReceiver(batteryReceiver, filter);
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

private void monitorBatteryState() {
    battReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            StringBuilder sb = new StringBuilder();

            int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); // charge level from 0 to scale inclusive
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Max value for charge level
            int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
            int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, -1);
            boolean present = intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false);
            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); //0 if the device is not plugged in; 1 if plugged into an AC power adapter; 2 if plugged in via USB.
            //                int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1); // voltage in millivolts
            nBatteryTemp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1); // current battery temperature in tenths of a degree Centigrade
            //                String technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY);

            nChargeLevel = -1; // percentage, or -1 for unknown
            if (rawlevel >= 0 && scale > 0) {
                nChargeLevel = (rawlevel * 100) / scale;
            }// www  .j  a va  2  s . c o m

            if (plugged > 0)
                sACStatus = "ONLINE";
            else
                sACStatus = "OFFLINE";

            if (present == false)
                sb.append("NO BATTERY");
            else {
                if (nChargeLevel < 10)
                    sb.append("Critical");
                else if (nChargeLevel < 33)
                    sb.append("LOW");
                else if (nChargeLevel > 80)
                    sb.append("HIGH");
            }

            if (BatteryManager.BATTERY_HEALTH_OVERHEAT == health) {
                sb.append("Overheated ");
                sb.append((((float) (nBatteryTemp)) / 10));
                sb.append("(C)");
            } else {
                switch (status) {
                case BatteryManager.BATTERY_STATUS_UNKNOWN:
                    // old emulator; maybe also when plugged in with no battery
                    if (present == true)
                        sb.append(" UNKNOWN");
                    break;
                case BatteryManager.BATTERY_STATUS_CHARGING:
                    sb.append(" CHARGING");
                    break;
                case BatteryManager.BATTERY_STATUS_DISCHARGING:
                    sb.append(" DISCHARGING");
                    break;
                case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
                    sb.append(" NOTCHARGING");
                    break;
                case BatteryManager.BATTERY_STATUS_FULL:
                    sb.append(" FULL");
                    break;
                default:
                    if (present == true)
                        sb.append("Unknown");
                    break;
                }
            }

            sPowerStatus = sb.toString();
        }
    };

    IntentFilter battFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(battReceiver, battFilter);
}

From source file:com.droid.app.fotobot.FotoBot.java

/**
 *  ? ?. ?  ,     battery_level.//from   w w w  .j  a va2 s .  c om
 */
public void batteryLevel() {

    BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            //context.unregisterReceiver(this);

            int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            battery_temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)) / 10.0f;
            battery_level = -1;
            if (rawlevel >= 0 && scale > 0) {
                battery_level = (rawlevel * 100) / scale;
            }

            //   int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
            //  isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
            //   if (VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN) {
            //       isPlugged = isPlugged || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
            //   }

        }
    };

    IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(batteryLevelReceiver, batteryLevelFilter);

}