我想访问电池的详细信息,以便我可以更改它。 例如,显示80%电池而不是50%。
如何在我的代码中访问它?
提前致谢! DVIR
答案 0 :(得分:2)
private Handler handler = new Handler;
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
int level = intent.getIntExtra(BatteryMenter code hereanager.EXTRA_LEVEL, 0);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
Log.i(TAG, "level: " + level + "; scale: " + scale);
int percent = (level*100)/scale;
final String text = String.valueOf(percent) + "%";enter code here
handler.post( new Runnable() {
public void run() {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
});
}
};