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:rus.cpuinfo.AndroidDepedentModel.BatteryInfo.java

@NonNull
private String getBatteryTemparature() {
    Integer temperature = getIntExtra(BatteryManager.EXTRA_TEMPERATURE);
    return temperature == -1 ? StringUtils.EMPTY : String.valueOf(temperature / 10);
}

From source file:com.hmatalonga.greenhub.managers.sampling.DataEstimator.java

@Override
public void onReceive(Context context, Intent intent) {
    if (context == null) {
        LOGE(TAG, "Error, context is null");
        return;// w w w  .j  av  a  2 s . c o  m
    }

    if (intent == null) {
        LOGE(TAG, "Data Estimator error, received intent is null");
        return;
    }

    LOGI(TAG, "onReceive action => " + intent.getAction());

    if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
        try {
            level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            mHealth = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
            plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            present = intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
            technology = intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
            temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)) / 10;
            voltage = ((float) intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0)) / 1000;
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        // We don't send battery level alerts here because we need to check if the level changed
        // So we verify that inside the DataEstimator Service

        if (temperature > SettingsUtils.fetchTemperatureWarning(context)) {
            if (SettingsUtils.isBatteryAlertsOn(context) && SettingsUtils.isTemperatureAlertsOn(context)) {

                // Check temperature limit rate
                Calendar lastAlert = Calendar.getInstance();
                long lastSavedTime = SettingsUtils.fetchLastTemperatureAlertDate(context);

                // Set last alert time with saved preferences
                if (lastSavedTime != 0) {
                    lastAlert.setTimeInMillis(lastSavedTime);
                }
                int minutes = SettingsUtils.fetchTemperatureAlertsRate(context);

                lastAlert.add(Calendar.MINUTE, minutes);

                // If last saved time isn't default and now is after limit rate then notify
                if (lastSavedTime == 0 || Calendar.getInstance().after(lastAlert)) {
                    // Notify for temperature alerts...
                    if (temperature > SettingsUtils.fetchTemperatureHigh(context)) {
                        Notifier.batteryHighTemperature(context);
                        SettingsUtils.saveLastTemperatureAlertDate(context, System.currentTimeMillis());
                    } else if (temperature <= SettingsUtils.fetchTemperatureHigh(context)
                            && temperature > SettingsUtils.fetchTemperatureWarning(context)) {
                        Notifier.batteryWarningTemperature(context);
                        SettingsUtils.saveLastTemperatureAlertDate(context, System.currentTimeMillis());
                    }
                }
            }
        }
    }

    // On some phones, scale is always 0.
    if (scale == 0)
        scale = 100;

    if (level > 0) {
        Inspector.setCurrentBatteryLevel(level, scale);

        // Location updates disabled for now
        // requestLocationUpdates();

        // Update last known location...
        // if (lastKnownLocation == null) {
        //    lastKnownLocation = LocationInfo.getLastKnownLocation(context);
        // }

        Intent service = new Intent(context, DataEstimatorService.class);
        service.putExtra("OriginalAction", intent.getAction());
        service.fillIn(intent, 0);

        if (SettingsUtils.isPowerIndicatorShown(context)) {
            LOGI(TAG, "Updating notification status bar");
            Notifier.updateStatusBar(context);
        }

        EventBus.getDefault().post(new BatteryLevelEvent(level));

        startWakefulService(context, service);
    }
}

From source file:hmatalonga.greenhub.managers.sampling.DataEstimator.java

@Override
public void onReceive(Context context, Intent intent) {
    if (context == null) {
        LOGE(TAG, "Error, context is null");
        return;/*from  w  w w. j  a v  a 2s  . c  o  m*/
    }

    if (intent == null) {
        LOGE(TAG, "Data Estimator error, received intent is null");
        return;
    }

    LOGI(TAG, "onReceive action => " + intent.getAction());

    if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
        try {
            level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
            plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            present = intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
            technology = intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
            temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)) / 10;
            voltage = ((float) intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0)) / 1000;
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        if (SettingsUtils.isBatteryAlertsOn(context)) {
            // Notify for temperature alerts...
            if (temperature > 45) {
                Notifier.batteryHighTemperature(context);
            } else if (temperature <= 45 && temperature > 35) {
                Notifier.batteryWarningTemperature(context);
            }
        }

        if (SettingsUtils.isPowerIndicatorShown(context)) {
            Notifier.updateStatusBar(context);
        }
    }

    // On some phones, scale is always 0.
    if (scale == 0)
        scale = 100;

    if (level > 0) {
        Inspector.setCurrentBatteryLevel(level, scale);

        // Location updates disabled for now
        // requestLocationUpdates();

        // Update last known location...
        // if (lastKnownLocation == null) {
        //    lastKnownLocation = LocationInfo.getLastKnownLocation(context);
        // }

        Intent service = new Intent(context, DataEstimatorService.class);
        service.putExtra("OriginalAction", intent.getAction());
        service.fillIn(intent, 0);
        service.putExtra("distance", distance);

        EventBus.getDefault().post(new BatteryLevelEvent(level));

        startWakefulService(context, service);
    }
}

From source file:mx.klozz.xperience.tweaker.fragments.BatteryInfo.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity();/*from   w ww .j av a2 s  .  c o  m*/
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    batteryinfoReveiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
            int leve = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
            int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
            int Temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);

            level = leve * scale / 100;

            mBattery_Percent.setText(level + "%");//Mostraremos el porcentaje de bateria

            //Para los ajustes de voltaje siempre y cuando el kernel soporte dicha funcion.
            if (new File(BAT_VOLT_PATH).exists()) {
                int volt = Integer.parseInt(Helpers.LeerUnaLinea(BAT_VOLT_PATH));
                if (volt > 5000)
                    volt = (int) Math.round(volt / 1000.0); //Microvolts :)
                mBattery_volt.setText(volt + " mV");
            }

            switch ((int) Math.ceil(level / 20.0)) {
            case 0:
                mBatteryIcon.setImageResource(R.drawable.battery0);
                break;
            case 1:
                mBatteryIcon.setImageResource(R.drawable.battery1);
                break;
            case 2:
                mBatteryIcon.setImageResource(R.drawable.battery2);
                break;
            case 3:
                mBatteryIcon.setImageResource(R.drawable.battery3);
                break;
            case 4:
                mBatteryIcon.setImageResource(R.drawable.battery4);
                break;
            case 5:
                mBatteryIcon.setImageResource(R.drawable.battery5);
                break;
            }

            mBattery_Status.setText(
                    (Temp / 10) + " C " + getResources().getStringArray(R.array.batt_status)[status]);
        }
    };
    setRetainInstance(true);
    setHasOptionsMenu(true);
}

From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity();//  w w  w .j  ava2  s.  c  o  m
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    batteryInfoReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            //int  health= intent.getIntExtra(BatteryManager.EXTRA_HEALTH,0);
            //String  technology= intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
            //boolean  present= intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            //int  rawvoltage= intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE,0);

            plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
            int lev = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
            int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
            int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);

            level = lev * scale / 100;
            mbattery_percent.setText(level + "%");
            if (new File(BAT_VOLT_PATH).exists()) {
                int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH));
                if (volt > 5000)
                    volt = (int) Math.round(volt / 1000.0);// in microvolts
                mbattery_volt.setText(volt + " mV");
            }
            switch ((int) Math.ceil(level / 20.0)) {
            case 0:
                mBattIcon.setImageResource(R.drawable.battery_0);
                break;
            case 1:
                mBattIcon.setImageResource(R.drawable.battery_1);
                break;
            case 2:
                mBattIcon.setImageResource(R.drawable.battery_2);
                break;
            case 3:
                mBattIcon.setImageResource(R.drawable.battery_3);
                break;
            case 4:
                mBattIcon.setImageResource(R.drawable.battery_4);
                break;
            case 5:
                mBattIcon.setImageResource(R.drawable.battery_5);
                break;
            }
            mbattery_status.setText(
                    (temperature / 10) + "C  " + getResources().getStringArray(R.array.batt_status)[status]);
        }
    };
    //getActivity().registerReceiver(batteryInfoReceiver,new IntentFilter(Intent.ACTION_BATTERY_CHANGED) );
    setRetainInstance(true);
    setHasOptionsMenu(true);

}

From source file:org.openchaos.android.fooping.service.PingService.java

@Override
protected void onHandleIntent(Intent intent) {
    String clientID = prefs.getString("ClientID", "unknown");
    long ts = System.currentTimeMillis();

    Log.d(tag, "onHandleIntent()");

    // always send ping
    if (true) {//from  w  w  w .j a v  a 2s . co  m
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "ping");
            json.put("ts", ts);

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
    // http://developer.android.com/reference/android/os/BatteryManager.html
    if (prefs.getBoolean("UseBattery", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "battery");
            json.put("ts", ts);

            Intent batteryStatus = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
            if (batteryStatus != null) {
                JSONObject bat_data = new JSONObject();

                int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                if (level >= 0 && scale > 0) {
                    bat_data.put("pct", roundValue(((double) level / (double) scale) * 100, 2));
                } else {
                    Log.w(tag, "Battery level unknown");
                    bat_data.put("pct", -1);
                }
                bat_data.put("health", batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1));
                bat_data.put("status", batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1));
                bat_data.put("plug", batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1));
                bat_data.put("volt", batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1));
                bat_data.put("temp", batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1));
                bat_data.put("tech", batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY));
                // bat_data.put("present", batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false));

                json.put("battery", bat_data);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/guide/topics/location/strategies.html
    // http://developer.android.com/reference/android/location/LocationManager.html
    if (prefs.getBoolean("UseGPS", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "loc_gps");
            json.put("ts", ts);

            if (lm == null) {
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            }

            Location last_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (last_loc != null) {
                JSONObject loc_data = new JSONObject();

                loc_data.put("ts", last_loc.getTime());
                loc_data.put("lat", last_loc.getLatitude());
                loc_data.put("lon", last_loc.getLongitude());
                if (last_loc.hasAltitude())
                    loc_data.put("alt", roundValue(last_loc.getAltitude(), 4));
                if (last_loc.hasAccuracy())
                    loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4));
                if (last_loc.hasSpeed())
                    loc_data.put("speed", roundValue(last_loc.getSpeed(), 4));
                if (last_loc.hasBearing())
                    loc_data.put("bearing", roundValue(last_loc.getBearing(), 4));

                json.put("loc_gps", loc_data);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    if (prefs.getBoolean("UseNetwork", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "loc_net");
            json.put("ts", ts);

            if (lm == null) {
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            }

            Location last_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (last_loc != null) {
                JSONObject loc_data = new JSONObject();

                loc_data.put("ts", last_loc.getTime());
                loc_data.put("lat", last_loc.getLatitude());
                loc_data.put("lon", last_loc.getLongitude());
                if (last_loc.hasAltitude())
                    loc_data.put("alt", roundValue(last_loc.getAltitude(), 4));
                if (last_loc.hasAccuracy())
                    loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4));
                if (last_loc.hasSpeed())
                    loc_data.put("speed", roundValue(last_loc.getSpeed(), 4));
                if (last_loc.hasBearing())
                    loc_data.put("bearing", roundValue(last_loc.getBearing(), 4));

                json.put("loc_net", loc_data);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/reference/android/net/wifi/WifiManager.html
    if (prefs.getBoolean("UseWIFI", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "wifi");
            json.put("ts", ts);

            if (wm == null) {
                wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            }

            List<ScanResult> wifiScan = wm.getScanResults();
            if (wifiScan != null) {
                JSONArray wifi_list = new JSONArray();

                for (ScanResult wifi : wifiScan) {
                    JSONObject wifi_data = new JSONObject();

                    wifi_data.put("BSSID", wifi.BSSID);
                    wifi_data.put("SSID", wifi.SSID);
                    wifi_data.put("freq", wifi.frequency);
                    wifi_data.put("level", wifi.level);
                    // wifi_data.put("cap", wifi.capabilities);
                    // wifi_data.put("ts", wifi.timestamp);

                    wifi_list.put(wifi_data);
                }

                json.put("wifi", wifi_list);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // TODO: cannot poll sensors. register receiver to cache sensor data
    // http://developer.android.com/guide/topics/sensors/sensors_overview.html
    // http://developer.android.com/reference/android/hardware/SensorManager.html
    if (prefs.getBoolean("UseSensors", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "sensors");
            json.put("ts", ts);

            if (sm == null) {
                sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            }

            List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ALL);
            if (sensors != null) {
                JSONArray sensor_list = new JSONArray();

                for (Sensor sensor : sensors) {
                    JSONObject sensor_info = new JSONObject();

                    sensor_info.put("name", sensor.getName());
                    sensor_info.put("type", sensor.getType());
                    sensor_info.put("vendor", sensor.getVendor());
                    sensor_info.put("version", sensor.getVersion());
                    sensor_info.put("power", roundValue(sensor.getPower(), 4));
                    sensor_info.put("resolution", roundValue(sensor.getResolution(), 4));
                    sensor_info.put("range", roundValue(sensor.getMaximumRange(), 4));

                    sensor_list.put(sensor_info);
                }

                json.put("sensors", sensor_list);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
    // http://developer.android.com/reference/android/net/ConnectivityManager.html
    if (prefs.getBoolean("UseConn", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "conn");
            json.put("ts", ts);

            if (cm == null) {
                cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            }

            // TODO: add active/all preferences below UseConn
            if (prefs.getBoolean("UseConnActive", true)) {
                NetworkInfo net = cm.getActiveNetworkInfo();
                if (net != null) {
                    JSONObject net_data = new JSONObject();

                    net_data.put("type", net.getTypeName());
                    net_data.put("subtype", net.getSubtypeName());
                    net_data.put("connected", net.isConnected());
                    net_data.put("available", net.isAvailable());
                    net_data.put("roaming", net.isRoaming());
                    net_data.put("failover", net.isFailover());
                    if (net.getReason() != null)
                        net_data.put("reason", net.getReason());
                    if (net.getExtraInfo() != null)
                        net_data.put("extra", net.getExtraInfo());

                    json.put("conn_active", net_data);
                }
            }

            if (prefs.getBoolean("UseConnAll", false)) {
                NetworkInfo[] nets = cm.getAllNetworkInfo();
                if (nets != null) {
                    JSONArray net_list = new JSONArray();

                    for (NetworkInfo net : nets) {
                        JSONObject net_data = new JSONObject();

                        net_data.put("type", net.getTypeName());
                        net_data.put("subtype", net.getSubtypeName());
                        net_data.put("connected", net.isConnected());
                        net_data.put("available", net.isAvailable());
                        net_data.put("roaming", net.isRoaming());
                        net_data.put("failover", net.isFailover());
                        if (net.getReason() != null)
                            net_data.put("reason", net.getReason());
                        if (net.getExtraInfo() != null)
                            net_data.put("extra", net.getExtraInfo());

                        net_list.put(net_data);
                    }

                    json.put("conn_all", net_list);
                }
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    if (!PingServiceReceiver.completeWakefulIntent(intent)) {
        Log.w(tag, "completeWakefulIntent() failed. no active wake lock?");
    }
}

From source file:fr.free.coup2lapan.ActualStateActivity.java

public BatteryStat getBatteryStatus() {

    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent status = this.registerReceiver(null, ifilter);

    BatteryStat batterystat = new BatteryStat(status.getIntExtra(BatteryManager.EXTRA_LEVEL, 0),
            status.getIntExtra(BatteryManager.EXTRA_SCALE, 0),
            status.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0),
            status.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0),
            status.getIntExtra(BatteryManager.EXTRA_STATUS, 0),
            status.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0),
            status.getIntExtra(BatteryManager.EXTRA_HEALTH, 0),
            status.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT) ? 1 : 0,
            DateFormat.getDateInstance(2, localeFR).format(new Date())
                    + DateFormat.getTimeInstance(2, localeFR).format(new Date()),
            status.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY));

    return batterystat;
}

From source file:hmatalonga.greenhub.managers.sampling.DataEstimator.java

public void getCurrentStatus(final Context context) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, ifilter);
    assert batteryStatus != null;

    level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
    health = batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
    plugged = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
    present = batteryStatus.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
    status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
    technology = batteryStatus.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
    temperature = (float) (batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) / 10);
    voltage = (float) (batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0) / 1000);
}

From source file:eu.liveGov.gordexola.urbanplanning.activities.MainActivity.java

@SuppressLint("NewApi")
@Override/*  w  ww .j  a v a 2  s  . com*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Process process = Runtime.getRuntime().exec("logcat -c");
    } catch (IOException e) {
        Log.e("MainActivity", "I was unable to clear LogCat");
    }
    _savedInstanceState = savedInstanceState;
    configureLogbackDirectly();

    tracker = EasyTracker.getInstance(this);
    setContentView(R.layout.activity_main);
    initialiseTabHost();
    initialisePager();
    ctx = this;

    //------ Location Service Start --------------------
    Functions.startLocationService(ctx);

    //------------ Measure kb downloaded ----------------
    uid = this.getApplicationInfo().uid;
    mStartRX = TrafficStats.getUidRxBytes(uid);
    mStartTX = TrafficStats.getUidTxBytes(uid);

    //------------ Menu hard or soft key ------------------
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        boolean hasMenuKey = ViewConfiguration.get(ctx).hasPermanentMenuKey();

        ActionBar actionBar = getActionBar();
        if (!hasMenuKey) {
            actionBar.show();
        } else {
            actionBar.hide();

        }
    }

    //------------------ Temperature -----------------------------------
    mReceiver_Temperature = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
            if (temperature > 450) {
                String mes = getString(R.string.tempwarn);
                int fullstopIndex = mes.indexOf(".");

                mes = mes.replace("XXXXX", Float.toString((((float) temperature) / 10)) + "\u2103");
                String mesA = mes.substring(0, fullstopIndex);
                Toast.makeText(ctx, mesA, Toast.LENGTH_LONG).show();
                String mesB = mes.substring(fullstopIndex + 2);
                Toast.makeText(ctx, mesB, Toast.LENGTH_LONG).show();
            }
        }
    };

    //--------------- Remove Transparency and Enable -------------------------------
    intentFilter = new IntentFilter("android.intent.action.MAIN"); // DataCh
    mReceiverARFinished = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String ARFINISHED = intent.getStringExtra("ARFINISHED");
            Integer ARDATAPLUSVal = intent.getIntExtra("DataPlus", 0);

            if (ARFINISHED != null) {
                Log.e("AR Finished", "ok 2");

                if (pbarGeneral != null)
                    pbarGeneral.setProgress(90);

                Message msg = new Message();
                msg.arg1 = 2;
                handlerDialog.sendMessage(msg);

            } else if (ARDATAPLUSVal != 0) {
                if (pbarGeneral != null) {

                    if (ARDATAPLUSVal > 90)
                        ARDATAPLUSVal = 90;

                    pbarGeneral.setProgress(ARDATAPLUSVal);
                } else {
                    if (ARDATAPLUSVal < 15) {
                        Message msg = new Message();
                        msg.arg1 = 1;
                        handlerDialog.sendMessage(msg);
                    }
                }
            }
        }
    };
    registerReceiver(mReceiverARFinished, intentFilter);

    //----- Handler for Redrawing Markers from update thread ------------
    handlerDialog = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.arg1 == 1) {
                if (progressReceiving == null) {
                    progressReceiving = ProgressDialog.show(ctx, "", "", true);
                    progressReceiving.setContentView(R.layout.dialog_transparent_progress);
                    pbarGeneral = (ProgressBar) progressReceiving.findViewById(R.id.allprogress);
                }
            } else {
                if (progressReceiving != null && progressReceiving.isShowing())
                    progressReceiving.dismiss();

                progressReceiving = null;
            }
            super.handleMessage(msg);
        }
    };

    if (Functions.checkInternetConnection(this) && Functions.hasNetLocationProviderEnabled(this)
            && Functions.hasGPSLocationProviderEnabled(this)) {
        // Show progress transparency
        Message msg = new Message();
        msg.arg1 = 1;
        handlerDialog.sendMessage(msg);
    }
}

From source file:com.hmatalonga.greenhub.managers.sampling.DataEstimator.java

public void getCurrentStatus(final Context context) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

    try {//from  w ww.java  2  s  .c om
        Intent batteryStatus = context.registerReceiver(null, ifilter);

        if (batteryStatus != null) {
            level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            mHealth = batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
            plugged = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            present = batteryStatus.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
            technology = batteryStatus.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
            temperature = (float) (batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) / 10);
            voltage = (float) (batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0) / 1000);
        }
    } catch (ReceiverCallNotAllowedException e) {
        LOGE(TAG, "ReceiverCallNotAllowedException from Notification Receiver?");
        e.printStackTrace();
    }
}