小编jle*_*man的帖子

Android不授予转储权限

为了监控电池使用情况等,我有执行一些dumpsys调用的代码,读取并解析输出以提取我感兴趣的数据.

dumpsys电池,dumpsys状态栏dumpsys电源都给我输出错误信息,如"权限拒绝:无法从pid转储电池服务......"此外,当应用程序启动时,日志中标记有一个项目"PackageManager"声明没有授予android.permissionDUMP权限包....(protectionLevel = 3 ...)"

但是,dumpsys cpuinfodumpsys netstat工作并给我正确的输出,这似乎是不一致的.

我能够从adb shell 生成dumpsys电池等,但是当我尝试以编程方式调用它时它不起作用.

我试过在HTC Nexus One手机和模拟器上运行它,并为每个手机获得相同的结果.奇怪的是,这个代码一天前在我的Nexus One上运行(在我从2.2升级到2.3之前),现在它没有.这是因为升级吗?

我尝试运行的代码示例如下:

        String command = "dumpsys battery";
    try {
        String s = null;
        Process process = Runtime.getRuntime().exec(command);


          BufferedReader stdInput = new BufferedReader(new 
                     InputStreamReader(process.getInputStream()));

                BufferedReader stdError = new BufferedReader(new 
                     InputStreamReader(process.getErrorStream()));

                // read the output from the command
                System.out.println("Here is the standard output of the command:\n");
                while ((s = stdInput.readLine()) != null) {
                    System.out.println(s);
                }

                // read …
Run Code Online (Sandbox Code Playgroud)

permissions android dump

3
推荐指数
1
解决办法
4180
查看次数

标签 统计

android ×1

dump ×1

permissions ×1