适用于apk应用的Dumpsys功能 [英] Dumpsys-like functionality for apk app

查看:188
本文介绍了适用于apk应用的Dumpsys功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种解决方案,可以从adb访问我们应用的内部状态以进行调试。
我已经使用了很多dumpsys来获取系统服务的内部状态所以现在我想知道我是否可以从我们的应用程序公开接口到adb。到目前为止,我唯一想到的是定期记录信息,然后只读logcat,但如果可能,我希望能够通过adb直接与应用程序进行交互,所以问题是如何在我们的应用程序中实现这一点。

I am looking for a solution to access the internal state of our app from adb for debugging purposes. I have used dumpsys a lot to get the internal state of system services so now I wonder if I can expose an interface from our app to adb. The only thing I have thought of so far is to log the information periodically and then just read logcat but if possible I would like to be able to interact directly with the app over adb so question is how to implement this in our app.

推荐答案

活动覆盖转储( )方法,例如:

@Override
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    //super.dump(prefix, fd, writer, args);
    writer.println();
    writer.println("command line arguments:");
    writer.format("length: %d, args: %s", args.length, Arrays.toString(args)).println();
}

然后开始你的活动并输入终端:

then start your Activity and type in the terminal:

adb shell dumpsys活动最重要的cmd行参数

或:

adb shell dumpsys活动顶部

如果您不想将任何参数传递给 dump()方法

if you don't want to pass any arguments to dump() method

其他组件中存在相同的方法,如服务 ContentProvider - 请参阅有关如何通过以下方式调用它们的官方文档使用 adb shell dumpsys活动命令,还有一些类具有可用于转储的 dump()方法他们的内部状态 - 例如 ApplicationInfo ActivityInfo Looper 处理程序 Binder Fragment 以及其他许多人

the same method exists in other components like Service or ContentProvider - see their official documentation on how to invoke them by using adb shell dumpsys activity command, also there are classes that have their dump() methods that can be used to dump their internal state - for example ApplicationInfo, ActivityInfo, Looper, Handler, Binder, Fragment and many others

这篇关于适用于apk应用的Dumpsys功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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