Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android hardware properties

How can I find hardware properties at runtime? I want to be able to know if the device has a physical keyboard, d-pad, trackball, etc.

like image 785
Jesús A. Álvarez Avatar asked Oct 15 '22 12:10

Jesús A. Álvarez


1 Answers

The preferred way of handling different hardware configurations seems to be to define different Resources and let Android pick the relevant one for the hardware. The documentation says:

You can supply different resources for your application to use depending on the UI language or hardware configuration on the device. Note that although you can include different string, layout, and other resources, the SDK does not expose methods to let you specify which alternate resource set to load. Android detects the proper set for the hardware and location, and loads them as appropriate.

However, there is nothing stopping you having a number of versions of a properties files in your application and using these to determine the hardward configuration. For example, one version of the file would contain dpad = true and another would have dpad = false and Android would pick the version of the file that matched the hardware and then you can read the dpad property. Admittedly, this would be rather tedious but I can't find easier way in the API to do this.

like image 111
Dave Webb Avatar answered Oct 20 '22 00:10

Dave Webb