简体   繁体   中英

Run Method On Multiple Devices at the Same Time - Android

I currently have an application where I push a button on the main activity and it does data collection. I need to do this on multiple devices at the same time. At the moment, i'm simply trying to do this manually by timing the button press (pushing my fingers down on each device at the same time). Obviously this doesn't work practically with more than 2 devices.

I'm wondering if there is a way for me to run the method (that is called when the button is pressed) on the devices at the same time from my PC?

I've seen a lot of answers use Appium for this kind of implementation, however, this seems a little too much for what i need. Is there not a way to run this via the command line (adp)? Or even just set up a small server that the devices connect to where the method is called?

Thank you.

您可以使用adb通过命令行单击按钮,但需要具有x和y坐标。

adb shell input tap x y

I added code to run the required method when a key was pressed. In the example code below i used F12.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    // KEYCODE_F12 = 142
    if (keyCode == KeyEvent.KEYCODE_F12) {
        findViewById(R.id.button).performClick();
    }

    return super.onKeyDown(keyCode, event);
}

The keycode number for F12 is 142.

adb devices is used to get the device ids that are connected. I could then use adb to input the key event into the devices:

start adb -s device_id1 shell input keyevent 142
start adb -s device_id2 shell input keyevent 142

The 'start' command is used to try and run the adb commands in parallel as much as possible to reduce the input lag to the devices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM