我对这些事情不熟悉。我怎么能为android制作一个java文件,它的功能就像股票kitkat电池指示器一样,通过单个图像和充电放电状态显示每个电池电量。如果可以的话,一步一步。谢谢!
答案 0 :(得分:0)
java代码根本不应该那么复杂......
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
// Are we charging / charged?
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
// How are we charging?
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
确定功率级别只需使用
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPct = level / (float)scale;
(来源:http://developer.android.com/training/monitoring-device-state/battery-monitoring.html)
除了基本的java知识外,这些应该是你需要的一切。 希望对你有所帮助;)
我自己几年前做过这件事,而最困难的部分是创造看起来不错的资产:P