2

I'm using UADetector in Google App Engine to parser this user agent like this:

Mozilla/5.0 (Linux; U; Android 2.2; en-ca; GT-P1000M Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

I can getOperatingSystem(), but i cannot get Android device name like GT-P1000M

How can i do this?

Thanks

Nam Vu
  • 5,669
  • 7
  • 58
  • 90

1 Answers1

3

This feature is often requested, but currently not implemented. To be able to implement this, we need a large list of User-Agent strings with informations about the corresponding device. I do not think we get this list, but we should be able to implement it partly (on demand).

In the last days, i've thought about to implement a set of known fragments, so that you can write something like this:

UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser();
UserAgent ua = parser.parse(anyUserAgentString);
if (ua.getKnownFragments().contains(KnownFragments.GT_P1000M)) {
    System.out.println("Seems to be a Galaxy Tab GT-P1000.");
} else if (ua.getKnownFragments().contains(KnownFragments.IPAD)) {
    System.out.println("Seems to be an iPad.");
} else if (ua.getKnownFragments().contains(KnownFragments.IPHONE)) {
    System.out.println("Seems to be an iPhone.");
}

If this feature could help you then please participate. This feature will be discussed on https://github.com/before/uadetector/issues/20. Any feedback or help is very appreciated.

(I'm the author of UADetector.)

before
  • 585
  • 6
  • 12
  • Thanks for your comment. Why dont you get it from user agent string? – Nam Vu Mar 05 '13 at 09:47
  • 1
    Because it depends on the device and/or software producers. The User-Agent in a HTTP header is poorly standardized and every producer implement it a little bit different. Thats one of the reasons why such a tool exists. More informations about the format of a User-Agent string can be obtained under http://stackoverflow.com/questions/2601372/what-is-the-standard-format-for-a-browsers-user-agent-string. – before Mar 05 '13 at 15:43