Android 从 adb 命令获取设备信息(如产品、型号)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22092118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get device information (such as product, model) from adb command
提问by Destructor
One way to achieve this is as follows:
实现此目的的一种方法如下:
adb devices -l
example output:
示例输出:
123abc12 device product:<id> model:<id> device:<id>
456abc45 device product:<id> model:<id> device:<id>
But this list's out all devices connected, but I want to get the information for a specific device.
I want information only about "123abc12". The output should be:
但是这个列表列出了所有连接的设备,但我想获取特定设备的信息。
我只想要有关“123abc12”的信息。输出应该是:
123abc12 device product:<id> model:<id> device:<id>
The second device should not be shown.
I have the device name i.e 123abc12, and it can be used to get the required information, but I don't know how.
Thanks.
不应显示第二个设备。
我有设备名称,即 123abc12,它可以用来获取所需的信息,但我不知道如何获取。
谢谢。
回答by Simo Kinnunen
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:
这将为您提供所有可用属性及其值的列表。一旦你知道你想要哪个属性,你可以将名称作为参数getprop
直接访问它的值,如下所示:
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
.
中的详细信息adb devices -l
由以下三个属性组成:ro.product.name
、ro.product.model
和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
).
请注意,ADB shell 以 结束行\r\n
,这取决于您的平台可能会或可能不会使访问确切值变得更加困难(例如,Nexus 7
您可能会得到Nexus 7\r
)。
回答by Substitut
Why don't you try to grep the return of your command ? Something like :
你为什么不尝试 grep 命令的返回?就像是 :
adb devices -l | grep 123abc12
It should return only the line you want to.
它应该只返回您想要的行。