Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

java - Detecting Device Type in a web application

We have a Java based application where in we want to detect the device type(mobile or desktop) for the device that is sending the request.

How is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You'll have to read the User-Agent header from the request and decide on that.

In vanilla servlet apps, a crude way of doing it is:

public void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
  if(request.getHeader("User-Agent").contains("Mobi")) {
    //you're in mobile land
  } else {
    //nope, this is probably a desktop
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...