以编程方式读取 Android logcat 时未显示所有数据 [英] Not all data shown when Android logcat is read programatically

查看:53
本文介绍了以编程方式读取 Android logcat 时未显示所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这样的问题,我尝试以编程方式从 logcat 获取数据.权限也已添加到清单文件:

代码:

 new Thread(new Runnable() {@覆盖公共无效运行(){尝试 {Process process = Runtime.getRuntime().exec("logcat ActivityManager:I *:S");BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));字符串线;while ((line = bufferedReader.readLine()) != null) {reactOnString(行);}} catch (IOException e) {}}}).开始();

但是我看不到其他应用何时启动.我正在等待像下面这样的字符串,但它们没有出现.

2260-2566/system_process I/ActivityManager: 为活动 com.android.email/.activity.MessageCompose 启动 proc com.android.email: pid=6460 uid=10011 gids={50011, 3003, 1015,1023, 1028}

附言此代码在服务中运行.

解决方案

我有一个坏消息要告诉你:从 JB 开始,READ_LOGS 不再像以前那样工作了:

https://groups.google.com/forum/?fromgroups#!topic/android-developers/6U4A5irWang

(滚动到 Android 开发人员 Dianne Hackborn 的帖子)和此视频:

Google I/O 2012 - 游戏开发者应该知道的十件事

(22:47) 为官方来源.

但是他的文件还没有被记录(READ_LOGS 权限没有报告这个)和仍然是混乱的根源.你现在只能访问你自己的日志,好消息是,你不再需要为它请求权限(如果你的目标是 Jelly Beans,就是这样......).>

我猜这是 Android 开发团队为了防止恶意应用监视用户,可能会获取敏感信息而采取的妥协(我敢打赌,每个应用开发者都不会在发布前清理自己的 Log.d 语句).

希望能帮到你

I have such a problem, I try to get data from logcat programatically. permission has also been added to manifest file:

<uses-permission android:name="android.permission.READ_LOGS"/>

Code:

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Process process = Runtime.getRuntime().exec("logcat ActivityManager:I *:S");
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    reactOnString(line);
                }
            } catch (IOException e) {
            }
        }
    }).start();

However I cannot see when other apps are launched. I am waiting for strings like the one below but they do not appear.

2260-2566/system_process                 I/ActivityManager: Start proc com.android.email for activity com.android.email/.activity.MessageCompose: pid=6460 uid=10011 gids={50011, 3003, 1015, 1023, 1028}

P.S. This code is run in service.

解决方案

I have bad news for you: as of JB, READ_LOGS don't just work as it did anymore:

https://groups.google.com/forum/?fromgroups#!topic/android-developers/6U4A5irWang

(scroll to the post of Dianne Hackborn, an Android Develper) and this video:

Google I/O 2012 - Ten Things Game Developers Should Know

(22:47) for official sources.

However his has not been yet documented (the READ_LOGS permission doesn't report this) and is yet a source of confusion. You can only access your own logs now, and the good news is, you don't need to request permissions for it anymore (if your are targetting Jelly Beans, that's it...).

I guess it's a compromise the Android Dev team took to prevent malicious app from spying on the user, perhaps getting sensitive information (I wouldn't bet every app developer cleans it's own Log.d statements before release).

Hope this helps

这篇关于以编程方式读取 Android logcat 时未显示所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆