List of usage examples for android.os BatteryManager BATTERY_STATUS_FULL
int BATTERY_STATUS_FULL
To view the source code for android.os BatteryManager BATTERY_STATUS_FULL.
Click Source Link
From source file:Main.java
public static boolean isCharging(Context context) { Intent batteryStatus = getBatteryStatus(context); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; }
From source file:Main.java
private static Boolean isCharging(Context context) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; }
From source file:Main.java
public static boolean isChargingOrFull(Intent batteryStatus) { int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; }
From source file:Main.java
public static boolean isCharging(Context context) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; }
From source file:Main.java
public static boolean isPowerConnected(Context context) { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = ((status == BatteryManager.BATTERY_STATUS_CHARGING) || (status == BatteryManager.BATTERY_STATUS_FULL)); return isCharging; }
From source file:com.owncloud.android.utils.ConnectivityUtils.java
public static boolean isCharging(Context context) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); int status = 0; if (batteryStatus != null) { status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); }//from w w w. ja v a 2s . c o m return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; }
From source file:fr.inria.ucn.collectors.SysStateCollector.java
/** * /*from ww w .j a va 2 s. co m*/ * @param c * @param ts * @param change */ @SuppressLint("NewApi") public void run(Context c, long ts, boolean change) { try { JSONObject data = new JSONObject(); data.put("on_screen_state_change", change); // this collection run was triggered by screen state change data.put("hostname", Helpers.getSystemProperty("net.hostname", "unknown hostname")); data.put("current_timezone", Time.getCurrentTimezone()); // general memory state ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); JSONObject mem = new JSONObject(); mem.put("available", mi.availMem); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mem.put("total", mi.totalMem); } mem.put("is_low", mi.lowMemory); data.put("memory", mem); // screen state PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE); data.put("screen_on", pm.isScreenOn()); // battery state IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent battery = c.registerReceiver(null, ifilter); int level = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = battery.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float pct = (float) (100.0 * level) / scale; int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL); int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; JSONObject batt = new JSONObject(); batt.put("level", level); batt.put("scale", scale); batt.put("pct", pct); batt.put("is_charging", isCharging); batt.put("usb_charge", usbCharge); batt.put("ac_charge", acCharge); data.put("battery", batt); // some proc stats data.put("cpu", getCpuStat()); data.put("loadavg", getLoadStat()); data.put("uptime", getUptimeStat()); // audio state data.put("audio", getAudioState(c)); // done Helpers.sendResultObj(c, "system_state", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }
From source file:org.opensilk.music.ui2.LauncherActivity.java
@Override protected void onStart() { super.onStart(); mPluginConnectionManager.onResume(); if (RxUtils.notSubscribed(chargingSubscription)) { //check if already plugged first IntentFilter filter2 = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent battChanged = registerReceiver(null, filter2); int battStatus = (battChanged != null) ? battChanged.getIntExtra(BatteryManager.EXTRA_STATUS, -1) : -1; if (battStatus == BatteryManager.BATTERY_STATUS_CHARGING || battStatus == BatteryManager.BATTERY_STATUS_FULL) { keepScreenOn(true);/* ww w . j ava2s . com*/ } // keep apprised of future plug events IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_POWER_CONNECTED); filter.addAction(Intent.ACTION_POWER_DISCONNECTED); chargingSubscription = AndroidObservable.fromBroadcast(this, filter).subscribe(new Action1<Intent>() { @Override public void call(Intent intent) { if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())) { keepScreenOn(true); } else if (Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())) { keepScreenOn(false); } } }); } }
From source file:org.proninyaroslav.libretorrent.core.utils.Utils.java
public static boolean isBatteryCharging(Context context) { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; }
From source file:org.wso2.emm.agent.api.DeviceState.java
/** * Conversion from charging status int to String can be done through this method. * * @param status integer representing the charging status. * @return String representing the charging status. *//*from w w w.j a v a2 s .c om*/ private String getStatus(int status) { String statusString = UNKNOWN; switch (status) { case BatteryManager.BATTERY_STATUS_CHARGING: statusString = CHARGING; break; case BatteryManager.BATTERY_STATUS_DISCHARGING: statusString = DISCHARGING; break; case BatteryManager.BATTERY_STATUS_FULL: statusString = FULL; break; case BatteryManager.BATTERY_STATUS_NOT_CHARGING: statusString = NOT_CHARGING; break; } return statusString; }