52ky 发表于 2022-5-11 12:17:56

安卓开发获取程序耗电排行.docx

本Demo是对2.3.3的settings源码的修改,主要针对没有研究过这部分源码的同学。
设置中获取手机电池电量排名的原理主要是通过读取电池记录文件来实现的。主要使用隐藏类android.os.BatteryStats和特殊包com.android.internal。
隐藏类很容易解决,主要是内部包。这个包不仅不在android.jar中,而且如果你找到这个包,放到android.jar中,你会发现它是没有用的。原因是 ADT 对这个包施加了限制。不允许使用。
一种解决方案是修改 ADT 以消除此限制。
另一种是不要把internal放在android.jar中,单独作为包导入到项目中,这样就不会受到限制。

(This demo is a modification of the settings source code of 2.3.3, mainly for students who have not studied this part of the source code.
The principle of obtaining the battery power ranking of mobile phone in setting is mainly realized by reading the battery record file. It mainly uses the hidden class Android os. Batterystats and special packages com android. internal。
Hidden classes are easy to solve, mainly internal packages. This package is not only not on Android Jar, and if you find this package, put it in Android Jar, you will find it useless. The reason is that ADT imposes restrictions on this package. Not allowed.
One solution is to modify the ADT to eliminate this limitation.
The other is not to put internal on Android Jar, which is imported into the project as a package separately, so it will not be restricted.)




页: [1]
查看完整版本: 安卓开发获取程序耗电排行.docx