List of usage examples for android.os BatteryManager EXTRA_LEVEL
String EXTRA_LEVEL
To view the source code for android.os BatteryManager EXTRA_LEVEL.
Click Source Link
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; }