In most cases, browser's UA string is enough to detect a device. However, there are a few exceptions to this approach when dealing with 3rd party, side-loaded browsers. These browsers typically use different User-Agent headers than the built-in browser and often use a generic string that does not identify the underlying device. In these cases, we recommend looking at additional browser-specific headers to accurately detect the underlying device. See here.
To make things better, we've been working with Opera to help draw up a standard to aid with the recognition of third-party browsers and applications. We have formalized a proposal to the HTTP Working Group and the IETF for an additional HTTP header to help identify the device behind HTTP requests. This header allows third-party browsers and native apps to explicitly identify the underlying device to ensure correct recognition by server-side solutions. If adopted, this (optional) header would become the standard way for third-party browsers and native apps to identify the devices on which they run, for the benefit of users and content publishers alike.
We've published the text of this RFC on GitHub here:
https://github.com/operasoftware/Device-Stock-UA-RFC.
This document will be submitted to the HTTP WG and IETF shortly. You can read Opera's comments on this over on their blog.