问题
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:
Why did I get 6-7 results when querying USBHub? Am I doing anything wrong here?
How can I filter my records to list only those USB ports which has an external device connected to it not 6-7 results?
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