Have a look at the Java library I wrote for this purpose: Yauaa
I made a very simple servlet where you can try it out to see if it gives the answers you are looking for: https://try.yauaa.basjes.nl/
It is Apache 2 licensed and published into Maven so using it in a Java application is really easy. It is currently used in production on one of the busiest websites of the Netherlands (where I work).
See this blog about this https://techlab.bol.com/making-sense-user-agent-string/