gpt4 book ai didi

android.permission.BATTERY_STATS 接口(interface)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:33 26 4
gpt4 key购买 nike

我想要更多关于 android.permission.BATTERY_STATS 的信息。什么可能性授予权限 android.permission.BATTERY_STATS。如果我可以在不声明此类许可的情况下读取电池电量的 android.intent.action.BATTERY_CHANGED Intent ,我就知道如何使用它。

最佳答案

使用此代码可以获得电池使用量、电池电压及其温度。

@Override
public void onCreate() {
BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
int scale = -1;
int level = -1;
int voltage = -1;
int temp = -1;
@Override
public void onReceive(Context context, Intent intent) {
level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
Log.e("BatteryManager", "level is "+level+"/"+scale+", temp is "+temp+", voltage is "+voltage);
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(batteryReceiver, filter);
}

关于android.permission.BATTERY_STATS 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9401410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com