本文整理匯總了Java中android.os.BatteryManager.BATTERY_STATUS_UNKNOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Java BatteryManager.BATTERY_STATUS_UNKNOWN屬性的具體用法?Java BatteryManager.BATTERY_STATUS_UNKNOWN怎麽用?Java BatteryManager.BATTERY_STATUS_UNKNOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.os.BatteryManager
的用法示例。
在下文中一共展示了BatteryManager.BATTERY_STATUS_UNKNOWN屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setStatus
private void setStatus(int statusValue) {
String status;
switch (statusValue) {
case BatteryManager.BATTERY_STATUS_CHARGING:
status = getString(R.string.battery_status_charging);
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
status = getString(R.string.battery_status_discharging);
break;
case BatteryManager.BATTERY_STATUS_FULL:
status = getString(R.string.battery_status_full);
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
status = getString(R.string.battery_status_not_charging);
break;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
default:
status = getString(R.string.battery_status_unknown);
}
mViewStatus.setValue(status);
mBatteryInfo.setStatus(status);
}
示例2: isCharging
/**
* Method to check if the device is charging.
*
* @return Returns true if device is either charging or full, false otherwise
*/
private boolean isCharging() {
try {
Intent batteryIntent = mContext.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (batteryIntent != null) {
int batteryPowerStatus = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
switch (batteryPowerStatus) {
case BatteryManager.BATTERY_STATUS_CHARGING:
case BatteryManager.BATTERY_STATUS_FULL:
return true;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
case BatteryManager.BATTERY_STATUS_DISCHARGING:
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
default:
return false;
}
}
} catch (Exception e) {
Log.e(TAG, "Exception occurred while isCharging: " + e);
}
return false;
}
示例3: translateBatteryStatus
public static String translateBatteryStatus(int batteryStatus) {
switch (batteryStatus) {
case BatteryManager.BATTERY_STATUS_CHARGING:
return "CHARGING";
case BatteryManager.BATTERY_STATUS_DISCHARGING:
return "DISCHARGING";
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
return "NOT CHARGING";
case BatteryManager.BATTERY_STATUS_FULL:
return "FULL";
case BatteryManager.BATTERY_STATUS_UNKNOWN:
return "STATUS UNKNOWN";
default:
return "UNKNOWN (" + batteryStatus + ")";
}
}
示例4: getBatteryStatusText
/** Get readable battery status */
private String getBatteryStatusText(int status) {
String statusString = getString(R.string.unknown);
switch (status) {
case BatteryManager.BATTERY_STATUS_UNKNOWN:
statusString = getString(R.string.unknown);
break;
case BatteryManager.BATTERY_STATUS_CHARGING:
statusString = getString(R.string.charging);
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
statusString = getString(R.string.discharging);
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
statusString = getString(R.string.not_charging);
break;
case BatteryManager.BATTERY_STATUS_FULL:
statusString = getString(R.string.full);
break;
}
return statusString;
}
示例5: getBatteryState
/**
* https://developer.android.com/training/monitoring-device-state/battery-monitoring.html
*/
public static int getBatteryState(Context context) {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
if (batteryStatus == null) {
return BatteryManager.BATTERY_STATUS_UNKNOWN;
}
return batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
}
示例6: reset
/** Reset when mod battery is not valid */
private void reset() {
modBattery = null;
modEfficiency = ModBattery.BATTERY_USAGE_TYPE_UNKNOWN;
modUsageType = ModBattery.BATTERY_USAGE_TYPE_UNKNOWN;
mod.status = BatteryManager.BATTERY_STATUS_UNKNOWN;
}
示例7: getBatteryInfo
private void getBatteryInfo() {
if (fabBatteryCharging != null) {
if (deviceStatus == BatteryManager.BATTERY_STATUS_CHARGING) {
fabBatteryCharging.setVisibility(View.VISIBLE);
fabBatteryCharging.setImageResource(R.drawable.ic_battery);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_DISCHARGING) {
fabBatteryCharging.setVisibility(View.GONE);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_FULL) {
fabBatteryCharging.setVisibility(View.GONE);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
fabBatteryCharging.setVisibility(View.GONE);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
fabBatteryCharging.setVisibility(View.GONE);
}
}
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
int counter = 0;
@Override
public void run() {
try {
if (counter <= level) {
progressBar.setProgress(counter);
progressBar.postDelayed(this, 10000);
counter++;
handler.postDelayed(this, 20);
} else {
handler.removeCallbacks(this);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 20);
tvBatteryTemperature.setText("".concat(String.valueOf(temperature)));
if (Validation.isRequiredField(technology)) {
tvBatteryType.setText("".concat(technology));
}
tvBatteryVoltage.setText("".concat(String.valueOf(voltage)));
tvBatteryScale.setText("".concat(String.valueOf(scale)));
tvBatteryLevel.setText("".concat(String.valueOf(level)).concat("%"));
if (health == 1) {
tvBatteryHealth.setText(mResources.getString(R.string.unknown));
} else if (health == 2) {
tvBatteryHealth.setText(mResources.getString(R.string.good));
} else if (health == 3) {
tvBatteryHealth.setText(mResources.getString(R.string.over_heated));
} else if (health == 4) {
tvBatteryHealth.setText(mResources.getString(R.string.dead));
} else if (health == 5) {
tvBatteryHealth.setText(mResources.getString(R.string.over_voltage));
} else if (health == 6) {
tvBatteryHealth.setText(mResources.getString(R.string.failed));
} else {
tvBatteryHealth.setText(mResources.getString(R.string.cold));
}
if (plugged == 1) {
tvPowerSource.setText(mResources.getString(R.string.ac_power));
} else {
tvPowerSource.setText(mResources.getString(R.string.battery));
}
}
示例8: getStatus
/**
* Method to resolve the battery status
*/
private void getStatus() {
if (DEBUG) {
MyLog.i(CLS_NAME, "getStatus");
}
if (batteryIntent != null) {
final SaiyResources sr = new SaiyResources(mContext, sl);
final int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
switch (status) {
case BatteryManager.BATTERY_STATUS_CHARGING:
int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED,
BatteryManager.BATTERY_STATUS_UNKNOWN);
switch (plugged) {
case BatteryManager.BATTERY_PLUGGED_AC:
setStatusResponse(sr.getString(ai.saiy.android.R.string.ac_charging));
break;
case BatteryManager.BATTERY_PLUGGED_USB:
setStatusResponse(sr.getString(ai.saiy.android.R.string.usb_charging));
break;
default:
setStatusResponse(sr.getString(ai.saiy.android.R.string.charging));
break;
}
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
setStatusResponse(sr.getString(ai.saiy.android.R.string.discharging));
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
setStatusResponse(sr.getString(ai.saiy.android.R.string.discharging));
break;
case BatteryManager.BATTERY_STATUS_FULL:
setStatusResponse(sr.getString(ai.saiy.android.R.string.fully_charged));
break;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
setStatusResponse(sr.getString(ai.saiy.android.R.string.currently_indeterminable));
break;
default:
setStatusResponse(sr.getString(ai.saiy.android.R.string.currently_indeterminable));
break;
}
sr.reset();
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "batteryIntent: null");
}
setAccessFailure();
}
}