How to detect mobile (iOS and Android) using JSP / Java?

Just wondering, did anyone meet this?

Basically, I want to detect iOS and Android using JSP and be able to conditionally add CSS and JS files to the page.

Any ideas?

+4
source share
4 answers

A better way would probably be with a User Agent . Actually, there is already a pretty similar question on SO, at least for iOS / Safari. Please note that there are other browsers in iOS, so you will need to look for their user agent strings.

Several UA lines listed on this site .

How to determine the server side of Mobile Safari using PHP?

+3
source

A very simple solution:

<% String userAgent = request.getHeader("user-agent"); if (userAgent.matches(".*Android.*")) { out.print("You're an Android!"); } else { out.print("You're something else..."); // iOS } %> 

Due to the very short else-statement, this should only be used if you are serving no more than iOS and Android.

+6
source

You can use the User Agent to determine if iOS or Android . Just search for relevant keywords like "Android" or "iPhone" or "iPad."

+1
source

All Articles