我怎样才能得到我的logcat设备显示来自所有进程的日志上 [英] How can I get logcat on my device to show logs from all processes

查看:149
本文介绍了我怎样才能得到我的logcat设备显示来自所有进程的日志上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个应用程序读取所有的日志我的设备上。我有一个客户/服务架构,我看到从客户端和服务流程的日志消息,但我没有看到在手机上的任何其他应用程序的任何消息(我不看其他的信息使用桌面logcat中)。

我是否需要root?

code片段

清单

 <使用-权限的Andr​​oid:名称=android.permission.READ_LOGS/>
 

日志读取器

 调用Runtime.getRuntime()EXEC(logcat的-c)WAITFOR()。

。工艺过程=调用Runtime.getRuntime()EXEC(logcat的-v长*:*);
BufferedReader中读取=
    新的BufferedReader(新的InputStreamReader(process.getInputStream()));
而(真){
    串nextLine = reader.readLine();
    如果(!nextLine.contains(LogWatcher-D)){
        Log.w(LogWatcher-D,见:+ nextLine);
    }

    //处理线
}
 

解决方案

在Android 4.1及更高版本,可以通过记录你的进程只能访问日志信息,除非你持有 READ_LOGS 许可。该权限要求要么您的应用程序所签署设备的固件,或者你的应用程序安装在系统分区上的相同签名密钥进行签名。

I'm trying to write an app that reads all logs on my device. I've got a client/service architecture, and I see log messages from both the client and service processes but I don't see any messages from any other applications on the phone (I do see other messages using the desktop logcat).

Do I need root?

Code Snippets

Manifest

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

Log Reader

Runtime.getRuntime().exec("logcat -c").waitFor();

Process process = Runtime.getRuntime().exec("logcat -v long *:*");
BufferedReader reader = 
    new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
    String nextLine = reader.readLine();
    if (!nextLine.contains("LogWatcher-D")) {
        Log.w("LogWatcher-D", "See: " + nextLine);
    }

    // Process line
}

解决方案

On Android 4.1+, you can only access log messages logged by your process, unless you hold the READ_LOGS permission. That permission requires either that your app be signed by the same signing key that signed the device's firmware, or that your app is installed on the system partition.

这篇关于我怎样才能得到我的logcat设备显示来自所有进程的日志上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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