-2

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

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

提前致谢!德维尔

4

1 回答 1

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

    }
};
于 2013-05-13T11:31:36.757 回答