you should check the header of the user agent that is sent by the HTTP request. Since there are so many user attacks, it is really difficult to recognize different devices / platforms. There is a free library for this that can help: wurfl
It basically maps the user agent to a device object that you can query for it. So in your layout you can use screen width / height, which image formats are supported, etc.
source share