从 adb 命令获取设备信息(如产品、型号)

实现这一目标的一种方法如下:

adb devices -l

示例输出:

123abc12               device product:<id> model:<id> device:<id>
456abc45               device product:<id> model:<id> device:<id>

但是这个列表是所有连接的设备,但是我想要得到一个特定设备的信息。< br/> 我只想知道“123ab12”的信息。产出应为:

123abc12               device product:<id> model:<id> device:<id>

不应显示第二个设备。
我有设备名称,即123abc 12,它可以用来获得所需的信息,但我不知道如何。
谢谢。

167078 次浏览

Why don't you try to grep the return of your command ? Something like :

adb devices -l | grep 123abc12

It should return only the line you want to.

The correct way to do it would be:

adb -s 123abc12 shell getprop

Which will give you a list of all available properties and their values. Once you know which property you want, you can give the name as an argument to getprop to access its value directly, like this:

adb -s 123abc12 shell getprop ro.product.model

The details in adb devices -l consist of the following three properties: ro.product.name, ro.product.model and ro.product.device.

Note that ADB shell ends lines with \r\n, which depending on your platform might or might not make it more difficult to access the exact value (e.g. instead of Nexus 7 you might get Nexus 7\r).