gpt4 book ai didi

android - 以编程方式获取连接到 adb 的 android 设备列表

转载 作者:太空狗 更新时间:2023-10-29 16:20:58 25 4
gpt4 key购买 nike

有没有办法以编程方式获取连接到 adb 的 android 设备列表?

我想在桌面应用程序上用 Java 来完成。我有 adb.exe 的路径,但对“adb devices”响应的解析似乎不是最好的主意。

有没有更靠谱的方法?

最佳答案

我是这样做的

try {
Process process = Runtime.getRuntime().exec("adb devices");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;

Pattern pattern = Pattern.compile("^([a-zA-Z0-9\\-]+)(\\s+)(device)");
Matcher matcher;

while ((line = in.readLine()) != null) {
if (line.matches(pattern.pattern())) {
matcher = pattern.matcher(line);
if (matcher.find())
System.out.println(matcher.group(1));
}
}
} catch (IOException e) {
e.printStackTrace();
}

关于android - 以编程方式获取连接到 adb 的 android 设备列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14880182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com