Just wondering if anyone has come across this?
Basically, Im looking to detect for iOS and Android using JSP and to be able to conditionally add CSS and JS files to the page.
Any ideas?
A very simple solution would be:
<%
String userAgent = request.getHeader("user-agent");
if (userAgent.matches(".*Android.*"))
{
out.print("You're an Android!");
}
else
{
out.print("You're something else..."); // iOS
}
%>
Because of the very short else-statement, this should be used only if you serve no more than iOS and Android.
Best way would probably be with the User Agent string. There's actually a pretty similar question on SO already, at least for iOS/Safari. Note that there are other browsers on iOS so you will need to look for their user agent strings as well.
Alot of UA strings listed on this site.
How do I detect Mobile Safari server side using PHP?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With