Example usage for android.os BatteryManager EXTRA_LEVEL

List of usage examples for android.os BatteryManager EXTRA_LEVEL

Introduction

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

Prototype

String EXTRA_LEVEL

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

Click Source Link

Document

Extra for android.content.Intent#ACTION_BATTERY_CHANGED : integer field containing the current battery level, from 0 to #EXTRA_SCALE .

Usage

From source file:com.harlie.android.sunshine.app.WeatherWatchFace.java

private int getBatteryLevel() {
    IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = registerReceiver(null, iFilter);
    if (batteryStatus == null) {
        return 0;
    }/*  w  ww . j  a  v  a 2s  .co m*/
    return batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
}

From source file:org.mariotaku.twidere.util.Utils.java

public static boolean isBatteryOkay(final Context context) {
    if (context == null)
        return false;
    final Context app = context.getApplicationContext();
    final IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    final Intent intent = app.registerReceiver(null, filter);
    if (intent == null)
        return false;
    final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0;
    final float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    final float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
    return plugged || level / scale > 0.15f;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static boolean isBatteryOkay(final Context context) {
    if (context == null)
        return false;
    final Context app = context.getApplicationContext();
    final IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    final Intent intent = app.registerReceiver(null, filter);
    if (intent == null)
        return false;
    final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
    final float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    final float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
    return plugged || level / scale > 0.15f;
}