安卓手机如何查看电池使用了多长时间!

安卓手机如何查看电池使用了多长时间!,第1张

vivo/iQOO手机电池的使用时间是不可以查看的,若是需要检测电池容量,建议携带手机前往当地vivo客户服务中心检测,进入浏览器搜索vivo官网--服务--服务中心--查看全部--选择省市查询当地的服务中心地址以及****。

1、CPU频率,CPU信息:/proc/cpuinfo和/proc/stat

通过读取文件/proc/cpuinfo系统CPU的类型等多种信息。

读取/proc/stat 所有CPU活动的信息来计算CPU使用率

下面我们就来讲讲如何通过代码来获取CPU频率:

复制代码 代码如下:

package comorangecpu;

import javaioBufferedReader;

import javaioFileNotFoundException;

import javaioFileReader;

import javaioIOException;

import javaioInputStream;

public class CpuManager {

// 获取CPU最大频率(单位KHZ)

// "/system/bin/cat" 命令行

// "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存储最大频率的文件的路径

public static String getMaxCpuFreq() {

String result = "";

ProcessBuilder cmd;

try {

String[] args = { "/system/bin/cat",

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };

cmd = new ProcessBuilder(args);

Process process = cmdstart();

InputStream in = processgetInputStream();

byte[] re = new byte[24];

while (inread(re) != -1) {

result = result + new String(re);

}

inclose();

} catch (IOException ex) {

exprintStackTrace();

result = "N/A";

}

return resulttrim();

}

// 获取CPU最小频率(单位KHZ)

public static String getMinCpuFreq() {

String result = "";

ProcessBuilder cmd;

try {

String[] args = { "/system/bin/cat",

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" };

cmd = new ProcessBuilder(args);

Process process = cmdstart();

InputStream in = processgetInputStream();

byte[] re = new byte[24];

while (inread(re) != -1) {

result = result + new String(re);

}

inclose();

} catch (IOException ex) {

exprintStackTrace();

result = "N/A";

}

return resulttrim();

}

// 实时获取CPU当前频率(单位KHZ)

public static String getCurCpuFreq() {

String result = "N/A";

try {

FileReader fr = new FileReader(

"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");

BufferedReader br = new BufferedReader(fr);

String text = brreadLine();

result = texttrim();

} catch (FileNotFoundException e) {

eprintStackTrace();

} catch (IOException e) {

eprintStackTrace();

}

return result;

}

// 获取CPU名字

public static String getCpuName() {

try {

FileReader fr = new FileReader("/proc/cpuinfo");

BufferedReader br = new BufferedReader(fr);

String text = brreadLine();

String[] array = textsplit(":s+", 2);

for (int i = 0; i < arraylength; i++) {

}

return array[1];

} catch (FileNotFoundException e) {

eprintStackTrace();

} catch (IOException e) {

eprintStackTrace();

}

return null;

}

}

2、内存:/proc/meminfo

复制代码 代码如下:

public void getTotalMemory() {

String str1 = "/proc/meminfo";

String str2="";

try {

FileReader fr = new FileReader(str1);

BufferedReader localBufferedReader = new BufferedReader(fr, 8192);

while ((str2 = localBufferedReaderreadLine()) != null) {

Logi(TAG, "---" + str2);

}

} catch (IOException e) {

}

}

3、Rom大小

复制代码 代码如下:

public long[] getRomMemroy() {

long[] romInfo = new long[2];

//Total rom memory

romInfo[0] = getTotalInternalMemorySize();

//Available rom memory

File path = EnvironmentgetDataDirectory();

StatFs stat = new StatFs(pathgetPath());

long blockSize = statgetBlockSize();

long availableBlocks = statgetAvailableBlocks();

romInfo[1] = blockSize availableBlocks;

getVersion();

return romInfo;

}

public long getTotalInternalMemorySize() {

File path = EnvironmentgetDataDirectory();

StatFs stat = new StatFs(pathgetPath());

long blockSize = statgetBlockSize();

long totalBlocks = statgetBlockCount();

return totalBlocks blockSize;

}

4、sdCard大小

复制代码 代码如下:

public long[] getSDCardMemory() {

long[] sdCardInfo=new long[2];

String state = EnvironmentgetExternalStorageState();

if (EnvironmentMEDIA_MOUNTEDequals(state)) {

File sdcardDir = EnvironmentgetExternalStorageDirectory();

StatFs sf = new StatFs(sdcardDirgetPath());

long bSize = sfgetBlockSize();

long bCount = sfgetBlockCount();

long availBlocks = sfgetAvailableBlocks();

sdCardInfo[0] = bSize bCount;//总大小

sdCardInfo[1] = bSize availBlocks;//可用大小

}

return sdCardInfo;

}

5、电池电量

复制代码 代码如下:

private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){

@Override

public void onReceive(Context context, Intent intent) {

int level = intentgetIntExtra("level", 0);

// level加%就是当前电量

}

};

registerReceiver(batteryReceiver, new IntentFilter(IntentACTION_BATTERY_CHANGED));

6、系统的版本信息

复制代码 代码如下:

public String[] getVersion(){

String[] version={"null","null","null","null"};

String str1 = "/proc/version";

String str2;

String[] arrayOfString;

try {

FileReader localFileReader = new FileReader(str1);

BufferedReader localBufferedReader = new BufferedReader(

localFileReader, 8192);

str2 = localBufferedReaderreadLine();

arrayOfString = str2split("s+");

version[0]=arrayOfString[2];//KernelVersion

localBufferedReaderclose();

} catch (IOException e) {

}

version[1] = BuildVERSIONRELEASE;// firmware version

version[2]=BuildMODEL;//model

version[3]=BuildDISPLAY;//system version

return version;

}

7、mac地址和开机时间

复制代码 代码如下:

public String[] getOtherInfo(){

String[] other={"null","null"};

WifiManager wifiManager = (WifiManager) mContextgetSystemService(ContextWIFI_SERVICE);

WifiInfo wifiInfo = wifiManagergetConnectionInfo();

if(wifiInfogetMacAddress()!=null){

other[0]=wifiInfogetMacAddress();

} else {

other[0] = "Fail";

}

other[1] = getTimes();

return other;

}

private String getTimes() {

long ut = SystemClockelapsedRealtime() / 1000;

if (ut == 0) {

ut = 1;

}

int m = (int) ((ut / 60) % 60);

int h = (int) ((ut / 3600));

return h + " " + mContextgetString(Rstringinfo_times_hour) + m + " "

+ mContextgetString(Rstringinfo_times_minute);

}

你想了解大致原理,就如同推荐答案一样,是靠电压。一般来说软件上有个表,电池电压从33V到42V,电量对应的从0到100%。而且并不是线性的对应关系。一般来说电池在37V的电压会停留的较长。你随便找快电池,看看商标上会注明37V或者38V。简单说就是电池电量用到37V以下时,电压会降的很快。所以,根本原理不是电压。

这个并不是安卓手机才有的方法,所有智能手机的电量检测都是这样。只不过有的复杂有的简单。正规点的品牌手机,电路中有一个叫电量计的芯片。而不叫电压计。否则只要一个普通的ADC检测芯片量量电压,就知道电量了。

在出厂之前,会对选用的电池进行测量,测出电池的充电放电曲线,根据曲线设计电量显示。电量计的软件算法其实很复杂,包括温度湿度校准。漏电流补偿。老化补偿校准。等等。

以上就是关于安卓手机如何查看电池使用了多长时间!全部的内容,包括:安卓手机如何查看电池使用了多长时间!、Android获取系统cpu信息,内存,版本,电量等信息、安卓手机是由什么来监测、显示电池电量的等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10123878.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存