Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Mac java executes the adb devices command

Shulou Source: shulou.com Published: 2022-06-03 07:57:47 11月23日 Update

Mac java executes the adb devices command

Recently, when you are doing mac+appium automation, you need to obtain the id of mobile devices through java, and you need to get it through code.

Import java.io.BufferedReader

Import java.io.IOException

Import java.io.InputStream

Import java.io.InputStreamReader

Import java.io.LineNumberReader

Import java.util.List

Public class Tet {

Public static void main (String [] args) {

Process process = null

String osName = System.getProperty ("os.name

")

String command = "/ Users/zhouhaijun/androidsdk/android-sdk-macosx/platform-tools/adb devices"; / / location of sdk

Try

{

Process=Runtime.getRuntime () exec (command)

InputStreamReader ir = new InputStreamReader (process.getInputStream ())

LineNumberReader input= new LineNumberReader (ir)

String line

While ((line=input.readLine ())! = null)

System.out.println (line)

}

Catch (IOException e) {

System.err.println ("IOException" + e.getMessage ())

}

System.out.println (osName+ "/ n")

}

}

Tags: Command code location location mobile phone device automation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information vpn macOS Redmi