Android应用:如何更改电池百分比?

时间:2013-05-13 09:37:10

标签: android

我想访问电池的详细信息,以便我可以更改它。 例如,显示80%电池而不是50%。

如何在我的代码中访问它?

提前致谢! DVIR

1 个答案:

答案 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();
            }
        });

    }
};