I think iOS does this automatically, not sure about the other OS. But if you just check the devices by their name using simple Javascript/jQuery, wouldn't that be sufficient?
Something like this:
$.browser.device = (/android|webos|iphone|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));