当前位置: 首页 > news >正文

Android 电池容量获取

Android 原生设置电池容量是在 power_profile.xml 中配置,此文件默认在 frameworks 目录下,也可能有 overlay 目录文件。

<!-- This is the battery capacity in mAh (measured at nominal voltage) --><item name="battery.capacity">1000</item>

在系统 frameworks/base/core/java/com/android/internal/os/PowerProfile.java 中包含电池相关信息接口,创建 PowerProfile 对象时,会加载保存 power_profile.xml 中配置的值。根据 xml item 类型分别保存在 sPowerItemMap 及 sPowerArrayMap 中。三方应用通过调用 getAveragePowerOrDefault 方法获取对应值。

    /*** Returns the average current in mA consumed by the subsystem, or the given* default value if the subsystem has no recorded value.** @param type         the subsystem type* @param defaultValue the value to return if the subsystem has no recorded value.* @return the average current in milliAmps.*/public double getAveragePowerOrDefault(String type, double defaultValue) {if (sPowerItemMap.containsKey(type)) {return sPowerItemMap.get(type);} else if (sPowerArrayMap.containsKey(type)) {return sPowerArrayMap.get(type)[0];} else {return defaultValue;}}

原生接口缺陷很明显,就是一个项目只能配置一个固定的电池容量值。如果项目有大小不同容量电池,就需要改动原生接口。通过读取电池节点中值动态获取。节点中值是直接获取电池中信息写入节点的,更准确点。

//电池容量节点
/sys/class/power_supply/battery/charge_full_design

http://www.lryc.cn/news/129241.html

相关文章:

  • 无涯教程-Perl - tell函数
  • 【论文综述】Transformer 综述
  • 博客摘录「 佛祖保佑,永无bug——springboot启动图案的修改方法」2023年6月8日
  • 【JavaEE进阶】SpringBoot 日志
  • conda - 调研介绍
  • keepalived集群
  • CentOS系统环境搭建(八)——CentOS7开机自动执行脚本(以MySQL为例)
  • re学习(31)BUUCTF-xx(多层加密)
  • HDFS的小文件影响及解决办法
  • 【前端】husky 的使用
  • Spring系列篇 -- Bean的生命周期
  • 分类预测 | MATLAB实现BO-BiGRU贝叶斯优化双向门控循环单元多输入分类预测
  • Linux权限系列--给普通用户添加某个命令的sudo权限
  • 11-数据结构-栈和队列的应用(C语言)
  • uni-app自定义多环境配置,动态修改appid
  • 04 - 分离头指针情况、理解HEAD和branch
  • C#__基本特性和使用
  • mysql(3)
  • 阿里巴巴常用的12个后端开发工具
  • php base64转图片保存本地
  • unity物体移动至指定位置
  • 详解C#-static void Main(string[] args)
  • 中大许少辉博士《乡村振兴战略下传统村落文化旅游设计》中国建筑工业出版社八一付梓。
  • Matplotlib数据可视化(五)
  • Python爬虫——requests_post请求
  • excel 下载方法封装
  • 按日,周,月,季,年统计;获取对应的时间段
  • 【eNSP】交换机(vlan和vlan间通信)
  • 2011年下半年 软件设计师 上午试卷2
  • Linux中安装MySQL8版本,安装MySQL步骤,MySQL8离线安装