检测Web应用程序中的设备类型 [英] Detecting Device Type in a web application

查看:120
本文介绍了检测Web应用程序中的设备类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个基于Java的应用程序,我们想要检测发送请求的设备的设备类型(移动设备或桌面设备)。

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?

推荐答案

你必须阅读用户代理来自请求的标头并决定它。

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

在vanilla servlet应用程序中,一种粗略的做法是:

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").indexOf("Mobile") != -1) {
    //you're in mobile land
  } else {
    //nope, this is probably a desktop
  }
}

这篇关于检测Web应用程序中的设备类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆