Android - 如何从正在运行的应用程序中找出运行该应用程序的设备是手机还是平板电脑

发布于 2024-10-16 19:01:52 字数 55 浏览 2 评论 0原文

有没有一种方法可以识别应用程序运行的设备是手机还是平板电脑?我们希望根据设备类型实现不同的行为。

Is there a method to identify if the device the app is running on is a phone or a tablet? We want to implement different behavior depending of the device type.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2024-10-23 19:01:52

如果您想要因屏幕尺寸而有所不同,则应该找到屏幕尺寸,但这并不容易,因为平板电脑有小屏幕,手机也有大屏幕。不过,当然可以获得屏幕尺寸。

您可以尝试使用 GSM 功能做一些事情。但同样,也有例外,比如可以调用的平板电脑。

我建议不要进行这种区分,并根据您的需要来定义它。屏幕尺寸、功能等。您可能会得到由“电话”和“桌子”组成的组,但您将更好地了解您的组是什么样的。

我仍然不确定如何定义“平板电脑”,并且您尝试的所有内容都需要该定义,但是如果您看一下 此链接,您可以看到,可能(快速阅读)那些认为自己是平板电脑的东西不会在其中识别自己作为移动设备的用户代理字符串。
但是:

  • 您需要获取设备浏览器的用户代理字符串。我猜想 Useragent 字符串可以更改,这使用起来是不合逻辑的
  • ,就像有些人不想要移动网站一样,所以他们更改了他们的代理字符串。这会影响你的行为,这很奇怪。

最后,我认为您需要定义平板电脑是什么,然后检查它!

If you want the differnce because of screensize, you should find screensize, but this is not really easy, as there are tablets with small screens and phones with large screens. Still, it is ofcourse possible to get screen size.

You could try to do do something with GSM capabilities. But again, there are exceptions, like tablets that can call..

I would advise against making this differentiation, and define it on the basis that you need. Screensize, capabilities etc. You might get groups that consist of both "phones" and "tables", but you'll have a much better knowledge of what your group is like.

I'm still not sure how to define a "tablet" and everything you try needs that definition, but if you take a look at this link, you can see that it might be (did a quick read) that things that consider themselves tablets do not identify themselves in a user-agent string as a mobile device.
But:

  • you would need to get the useragent string for the devices' browser. Which would be illogical to use i guess
  • Useragent strings can be changed, like some people don't want mobile sites, so they change their agent string. That would influence your behaviour, which is weird.

In the end I think you need to define what a tablet is, and then check for that!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文