zoukankan      html  css  js  c++  java
  • 安卓电量读取

    试了下51testing上的方法是各种报错啊,google官方提供的python也报错

    最后没有办法只有自己解析了http://blog.csdn.net/oujunli/article/details/37563067 这是官方的方法不知道你们能不能用

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;

    public class Battert {
    public static void readTxtFile(String filePath,String pac){
    try {
    String encoding="GBK";
    File file=new File(filePath);
    if(file.isFile() && file.exists()){ //判断文件是否存在
    InputStreamReader read = new InputStreamReader(
    new FileInputStream(file),encoding);//考虑到编码格式
    BufferedReader bufferedReader = new BufferedReader(read);
    String lineTxt = null;
    String uid=null;
    while((lineTxt = bufferedReader.readLine()) != null){
    //System.out.println(lineTxt);
    if (lineTxt.contains(pac)&&lineTxt.contains("proc")){
    lineTxt=lineTxt.split("=")[1].split(":")[0];
    uid=lineTxt;
    System.out.println("取得UId为"+uid);
    }
    if (lineTxt.contains("Uid")&&lineTxt.contains(uid)){
    lineTxt=lineTxt.split(":")[1];
    System.out.println(pac+"取得耗电量为"+lineTxt+"毫安时");
    }
    }
    read.close();
    }else{
    System.out.println("找不到指定的文件");
    }
    } catch (Exception e) {
    System.out.println("读取文件内容出错");
    e.printStackTrace();
    }

    }
    public static void main(String[] args){
    //需要先使用adb shell dumpsys batterystats --reset 初始化操作
    //使用一段时间后adb shell dumpsys batterystats > xxx.txt 得到一个txt
    //拿这个txt来进行结果分析,建议使用对比 具体数据可能无太大参考意义
    String filePath = "E:\download\battery-historian-master\xxx.txt";
    String pac="tiange.ktv.assistant";
    readTxtFile(filePath,pac);

    }


    }

  • 相关阅读:
    Java学习个人备忘录之继承
    Java学习个人备忘录之文档注释
    Java学习个人备忘录之数组工具类
    Java学习个人备忘录之关键字static
    Java学习个人备忘录之构造函数&this
    Java学习个人备忘录之面向对象概念
    Java学习个人备忘录之数组
    Java学习个人备忘录之入门基础
    hdoj1162-Eddy's picture(kruskal)
    hdoj1102-Constructing Roads(Kruskal)
  • 原文地址:https://www.cnblogs.com/tester-huang/p/4689771.html
Copyright © 2011-2022 走看看