List of usage examples for android.os BatteryManager BATTERY_PLUGGED_WIRELESS
int BATTERY_PLUGGED_WIRELESS
To view the source code for android.os BatteryManager BATTERY_PLUGGED_WIRELESS.
Click Source Link
From source file:Main.java
public static boolean isPowerConnected(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (intent == null) { return true; }/*from w ww .ja v a2s .c om*/ int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; }
From source file:Main.java
public static boolean isCharging(Context context) { IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, filter); int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_USB); boolean acCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_AC); boolean wirelessCharge = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { wirelessCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS); }/* w w w . j av a2 s .c om*/ return (usbCharge || acCharge || wirelessCharge); }
From source file:Main.java
/** * @return true is device is plugged at this moment, false otherwise. * @see #isPlugged(android.content.Context) *//* w w w.ja v a2 s. c om*/ @SuppressLint("InlinedApi") public static boolean isPlugged(@Nullable Intent intent) { if (intent == null) { return false; } final int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; }
From source file:org.wso2.emm.agent.api.DeviceState.java
/** * Conversion from plugged type int to String can be done through this method. * * @param plugged integer representing the plugged type. * @return String representing the plugged type. *///from w w w .j a v a 2s. com private String getPlugType(int plugged) { String plugType = UNKNOWN; switch (plugged) { case BatteryManager.BATTERY_PLUGGED_AC: plugType = AC; break; case BatteryManager.BATTERY_PLUGGED_USB: plugType = USB; break; case BatteryManager.BATTERY_PLUGGED_WIRELESS: plugType = WIRELESS; break; } return plugType; }
From source file:saphion.services.ForegroundService.java
public Status readBatteryStat() { Intent batteryIntent = getBaseContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int rawlevel = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); double scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); isconnected = (plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS); level = -1;/*from ww w . j av a 2 s . c o m*/ if (rawlevel >= 0 && scale > 0) { level = (int) ((rawlevel * 100) / scale); Log.d("rawLevel: " + rawlevel); Log.d("scale: " + scale); } if (mPref.getBoolean(PreferenceHelper.KEY_ONE_PERCENT_HACK, false)) { try { java.io.FileReader fReader = new java.io.FileReader( "/sys/class/power_supply/battery/charge_counter"); java.io.BufferedReader bReader = new java.io.BufferedReader(fReader); int charge_counter = Integer.valueOf(bReader.readLine()); bReader.close(); if (charge_counter > PreferenceHelper.CHARGE_COUNTER_LEGIT_MAX) { disableOnePercentHack("charge_counter is too big to be actual charge"); } else { if (charge_counter > 100) charge_counter = 100; level = charge_counter; } } catch (java.io.FileNotFoundException e) { /* * These error messages are only really useful to me and might * as well be left hardwired here in English. */ disableOnePercentHack("charge_counter file doesn't exist"); } catch (java.io.IOException e) { disableOnePercentHack("Error reading charge_counter file"); } } return new Status(level, isconnected); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Update the preference switch for {@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} setting. * * <p>//from ww w . j av a 2s.c o m * If either one of the {@link BatteryManager#BATTERY_PLUGGED_AC}, * {@link BatteryManager#BATTERY_PLUGGED_USB}, {@link BatteryManager#BATTERY_PLUGGED_WIRELESS} * values is set, we toggle the preference to true and update the setting value to * {@link #BATTERY_PLUGGED_ANY} * </p> */ private void updateStayOnWhilePluggedInPreference() { if (!mStayOnWhilePluggedInSwitchPreference.isEnabled()) { return; } boolean checked = false; final int currentState = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); checked = (currentState & (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS)) != 0; mDevicePolicyManager.setGlobalSetting(mAdminComponentName, Settings.Global.STAY_ON_WHILE_PLUGGED_IN, checked ? BATTERY_PLUGGED_ANY : DONT_STAY_ON); mStayOnWhilePluggedInSwitchPreference.setChecked(checked); }
From source file:saphion.services.ForegroundService.java
public int readbattery() { Intent batteryIntent = getApplicationContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int rawlevel = batteryIntent.getIntExtra("level", -1); double scale = batteryIntent.getIntExtra("scale", -1); int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); isconnected = (plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS); level = -1;//from w ww . ja v a 2 s. c o m if (rawlevel >= 0 && scale > 0) { level = (int) ((rawlevel * 100) / scale); Log.d("rawLevel: " + rawlevel); Log.d("scale: " + scale); } temperature = Functions.updateTemperature( (float) ((float) (batteryIntent.getIntExtra("temperature", 0)) / 10), mPref.getBoolean(PreferenceHelper.MAIN_TEMP, true), true); int inthealth = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0); health = ""; switch (inthealth) { case BatteryManager.BATTERY_HEALTH_COLD: health = "Cold"; break; case BatteryManager.BATTERY_HEALTH_DEAD: health = "Dead"; break; case BatteryManager.BATTERY_HEALTH_GOOD: health = "Good"; break; case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: health = "Over Voltage"; break; case BatteryManager.BATTERY_HEALTH_OVERHEAT: health = "Overheat"; break; case BatteryManager.BATTERY_HEALTH_UNKNOWN: health = "Unknown"; break; case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: health = "Unspecified failure"; break; } if (mPref.getBoolean(PreferenceHelper.KEY_ONE_PERCENT_HACK, false)) { try { java.io.FileReader fReader = new java.io.FileReader( "/sys/class/power_supply/battery/charge_counter"); java.io.BufferedReader bReader = new java.io.BufferedReader(fReader); int charge_counter = Integer.valueOf(bReader.readLine()); bReader.close(); if (charge_counter > PreferenceHelper.CHARGE_COUNTER_LEGIT_MAX) { disableOnePercentHack("charge_counter is too big to be actual charge"); } else { if (charge_counter > 100) charge_counter = 100; level = charge_counter; } } catch (java.io.FileNotFoundException e) { /* * These error messages are only really useful to me and might * as well be left hardwired here in English. */ disableOnePercentHack("charge_counter file doesn't exist"); } catch (java.io.IOException e) { disableOnePercentHack("Error reading charge_counter file"); } } return level; }