简体   繁体   English

如何获取通过C#.net(VS2010 / 4.0 +)通过USB连接的Android设备的OS版本和设备名称?

[英]How to get OS version and Device Name of an Android device connected via USB with C#.net (VS2010/4.0+)?

I want to build a windows application in C#.net which should identify the installed Adroid OS version (eg 4.0) and user friendly Device Name (eg Samsung Galaxy S3, Samsung Galaxy Tab 8.9 etc.) when you connect an Android device to your computer via USB. 我想在C#.net中构建Windows应用程序,当您将Android设备连接到计算机时,该应用程序应标识已安装的Adroid OS版本(例如4.0)和用户友好的设备名称(例如Samsung Galaxy S3,Samsung Galaxy Tab 8.9等)。通过USB。

I tried with the System.Management class to identify the connected USB devices on my machine, however, the problems I had were: 我尝试使用System.Management类来识别机器上已连接的USB设备,但是,我遇到的问题是:

I just have 3 USB ports and connected the Samsung Galaxy Tab 8.9 on one of the USB ports and tried to get the list of USB devices using USBhub WMI class and I got around 6-7 results in the list including the Samsung device. 我只有3个USB端口,并在其中一个USB端口上连接了Samsung Galaxy Tab 8.9,并尝试使用USBhub WMI class获取USB设备的列表,并且列表中大约有6-7个结果,包括三星设备。 So, the issues here are: 因此,这里的问题是:

  1. Why did I get 6-7 results when querying USBHub? 查询USBHub时为什么会得到6-7个结果? Am I doing anything wrong here? 我在这里做错什么吗?

  2. How can I filter my records to list only those USB ports which has an external device connected to it not 6-7 results? 如何过滤记录以仅列出那些连接了外部设备而不是6-7结果的USB端口?

  3. I could not find the correct/user friendly Device Name I was expecting (eg Samsung Galaxy Tab 8.9) and no way to get the Android version OS. 我找不到我期望的正确/用户友好的设备名称(例如Samsung Galaxy Tab 8.9),并且无法获取Android版本的操作系统。 I tried 'Caption' and 'Description' properties, but they have very generic information such as just 'Samsung'. 我尝试使用“标题”和“描述”属性,但是它们具有非常通用的信息,例如“三星”。 How can I get the user friendly device name and the installed Android OS version on the device. 如何获取用户友好的设备名称和设备上已安装的Android OS版本。

You can use the Android Debug Bridge from the Android SDK to query properties from the connected devices. 您可以使用Android SDK中的Android调试桥来查询所连接设备的属性。 You can simply launch the adb.exe process from within .NET and use the results. 您可以简单地从.NET内部启动adb.exe进程并使用结果。

For example adb.exe shell getprop ro.product.model will give you the model name, and adb.exe shell getprop ro.build.version.release will give you the Android version number. 例如, adb.exe shell getprop ro.product.model将为您提供模型名称,而adb.exe shell getprop ro.build.version.release将为您提供Android版本号。 To get a complete list of all available properties for a given device, you can also just run adb.exe shell getprop . 要获取给定设备的所有可用属性的完整列表,还可以只运行adb.exe shell getprop

Note that the property names are not really standardized and manufacturers are not required to put in valuable names. 请注意,属性名称并非真正标准化,并且不需要制造商使用有价值的名称。 It's common that the product model contains the device's code name or a product identifier that is not commonly used to identify the product among consumers. 通常,产品模型包含设备的代号或产品标识符,这些名称或标识符通常不用于在消费者之间标识产品。

I think we need to make changes into the device setting 我认为我们需要对设备设置进行更改

1> At your android, go to settings -> applications -> development 1>在您的android上,转到设置->应用程序->开发

2> Check USB Debugging 2>检查USB调试

3> Make sure your device driver is already installed. 3>确保已安装设备驱动程序。

Android version 4.2 and above comes with security which wont allow you to fire the ADB commands without making changes in the settings. Android 4.2及更高版本具有安全性,不允许您在不更改设置的情况下触发ADB命令。

Regards, Aryan 问候,雅利安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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