Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

java - Dumpsys-like functionality for apk app

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

in your Activity override dump() method, for example:

@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 activity top your cmd line arguments

or:

adb shell dumpsys activity top

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...