How I can link android activity change with adb ge

2019-07-09 01:04发布

for my project i need to do the following thing,

  1. get device touch event from adb getevent command.
  2. and at the same time i need to find something that collects the information of the application activity calls.

my goal is to find out upon each touch information if there is a change in activity in a particular app, detect that activity.

So, whenever a touch at (x,y) position happens getevent reports that, now if there is a button on that position it may call an activity change in the app, so i need to detect the change to new activity.

How this can be done? any idea?

1条回答
仙女界的扛把子
2楼-- · 2019-07-09 02:02

You can try this in a python script:

from subprocess import call

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()

# These show the package name of the currently running package and 
# the current activity's action. 
device.getProperty('am.current.package')
device.getProperty('am.current.action')

With monkeyrunner you can also click/ press on buttons using (x,y) coordinates.

Another way would be to look in the logcat output for activity changes. It should look like this: Displayed com.android.gallery3d/.app.MovieActivity whyen playing a video file from gallery.

Later edit:

You can use 'am.current.package' and 'am.current.action' to see the changes in the activities. You can use:

call('adb getevent', shell = True)  

to catch the click/ touch events. All in the same script.

查看更多
登录 后发表回答