本文整理汇总了Java中android.os.BatteryManager.BATTERY_PLUGGED_WIRELESS属性的典型用法代码示例。如果您正苦于以下问题:Java BatteryManager.BATTERY_PLUGGED_WIRELESS属性的具体用法?Java BatteryManager.BATTERY_PLUGGED_WIRELESS怎么用?Java BatteryManager.BATTERY_PLUGGED_WIRELESS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.os.BatteryManager
的用法示例。
在下文中一共展示了BatteryManager.BATTERY_PLUGGED_WIRELESS属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addBatteryStateTo
private void addBatteryStateTo(Collection<IoTDataField> dataFields) {
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent intent = mContext.registerReceiver(null, intentFilter);
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING;
IoTDataField.BooleanField chargingField = new IoTDataField.BooleanField("charging", isCharging);
dataFields.add(chargingField);
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
IoTDataField.BooleanField pluggedField = new IoTDataField.BooleanField("plugged", isPlugged);
dataFields.add(pluggedField);
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPercent = level / (float) scale;
// Scale to percents.
batteryPercent *= 100;
IoTDataField.IntField batteryPercentField = new IoTDataField.IntField("batteryPrecent", (int) batteryPercent);
dataFields.add(batteryPercentField);
}
示例2: isCharging
public static boolean isCharging(Context context) {
Bundle extras = getBatteryChangedExtras(context);
int plugged = extras != null ? extras.getInt(BatteryManager.EXTRA_PLUGGED, 0) : 0;
return plugged == BatteryManager.BATTERY_PLUGGED_AC
|| plugged == BatteryManager.BATTERY_PLUGGED_USB
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
&& plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS);
}
示例3: isConnectedToCharger
public static boolean isConnectedToCharger(Context context) {
Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (intent != null) {
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
} else return false;
}
示例4: getChargingSource
public final String getChargingSource() {
Intent intent = getBatteryStatusIntent();
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
switch (plugged) {
case BatteryManager.BATTERY_PLUGGED_AC:
return BATTERY_PLUGGED_AC;
case BatteryManager.BATTERY_PLUGGED_USB:
return BATTERY_PLUGGED_USB;
case BatteryManager.BATTERY_PLUGGED_WIRELESS:
return BATTERY_PLUGGED_WIRELESS;
default:
return BATTERY_PLUGGED_UNKNOWN;
}
}
示例5: translateBatteryPlugged
public static String translateBatteryPlugged(int batteryPlugged) {
switch (batteryPlugged) {
case 0:
return "UNPLUGGED";
case BatteryManager.BATTERY_PLUGGED_AC:
return "AC";
case BatteryManager.BATTERY_PLUGGED_USB:
return "USB";
case BatteryManager.BATTERY_PLUGGED_WIRELESS:
return "WIRELESS";
default:
return "UNKNOWN (" + batteryPlugged + ")";
}
}
示例6: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
final Intent mIntent = context.getApplicationContext()
.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (mIntent == null) return;
int chargePlug = mIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
boolean wirelessCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS;
if (acCharge) {
EventBus.getDefault().post(new PowerSourceEvent("ac"));
} else if (usbCharge) {
EventBus.getDefault().post(new PowerSourceEvent("usb"));
} else if (wirelessCharge) {
EventBus.getDefault().post(new PowerSourceEvent("wireless"));
}
} else if(intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) {
EventBus.getDefault().post(new PowerSourceEvent("unplugged"));
}
// Save a new Battery Session to the database
GreenHubDb database = new GreenHubDb();
LOGI(TAG, "Getting new session");
database.saveSession(Inspector.getBatterySession(context, intent));
database.close();
}
示例7: isCharging
private static boolean isCharging(final Context context) {
final Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
final int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
final boolean ac_usb_plugged = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
return ac_usb_plugged || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
}
示例8: getDetailedItems
public List<ItemDetails> getDetailedItems() {
List<ItemDetails> detailedItems = new ArrayList<>();
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = sContext.registerReceiver(null, ifilter);
//TODO: Change true to yes.
detailedItems.add(new ItemDetails("Present",
Boolean.valueOf(batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)).toString()));
detailedItems.add(new ItemDetails("Technology", batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY)));
detailedItems.add(new ItemDetails("Status", Integer.valueOf(batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1)).toString()));
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
boolean wirelessCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS;
String chargeType = "Not plugged";
if(usbCharge) {
chargeType = "USB Power";
} else if(acCharge) {
chargeType = "AC Power";
} else if(wirelessCharge) {
chargeType = "Wireless Power";
}
detailedItems.add(new ItemDetails("Charging", chargeType));
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPct = level / (float)scale;
int health = batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1);
String healthStatus = "";
if(health == BatteryManager.BATTERY_HEALTH_GOOD) {
healthStatus = "Good";
} else if(health == BatteryManager.BATTERY_HEALTH_OVERHEAT) {
healthStatus = "Over Heat";
} else if(health == BatteryManager.BATTERY_HEALTH_DEAD) {
healthStatus = "Dead";
} else if(health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE) {
healthStatus = "Over Voltage";
} else if(health == BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE) {
healthStatus = "Unspecified failure";
} else if(health == BatteryManager.BATTERY_HEALTH_COLD) {
healthStatus = "Cold";
} else {
healthStatus = "UNKNOWN";
}
//TODO: Decide if unsupported charger is attached.
detailedItems.add(new ItemDetails("Health", healthStatus));
detailedItems.add(new ItemDetails("Battery", Integer.valueOf((int)(batteryPct*100)).toString()+"%"));
float temp = ((float) batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0) / 10);
detailedItems.add(new ItemDetails("Temperature", Float.valueOf(temp).toString()+"°C"));
detailedItems.add(new ItemDetails("Voltage", Integer.valueOf(batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1)).toString()+"mV"));
return detailedItems;
}