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

心已入冬 提交于 2019-12-22 10:05:31

问题


I want to build a windows application in C#.net which should identify the installed Adroid OS version (e.g. 4.0) and user friendly Device Name (e.g. Samsung Galaxy S3, Samsung Galaxy Tab 8.9 etc.) when you connect an Android device to your computer via USB.

I tried with the System.Management class to identify the connected USB devices on my machine, however, the problems I had were:

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. So, the issues here are:

  1. Why did I get 6-7 results when querying USBHub? 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?

  3. I could not find the correct/user friendly Device Name I was expecting (e.g. Samsung Galaxy Tab 8.9) and no way to get the Android version OS. 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.


回答1:


You can use the Android Debug Bridge from the Android SDK to query properties from the connected devices. You can simply launch the adb.exe process from within .NET and use the results.

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. To get a complete list of all available properties for a given device, you can also just run 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.




回答2:


I think we need to make changes into the device setting

1> At your android, go to settings -> applications -> development

2> Check USB Debugging

3> Make sure your device driver is already installed.

Android version 4.2 and above comes with security which wont allow you to fire the ADB commands without making changes in the settings.

Regards, Aryan



来源:https://stackoverflow.com/questions/15303915/how-to-get-os-version-and-device-name-of-an-android-device-connected-via-usb-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!