且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-24 07:47:27

如果您希望因屏幕尺寸而有所不同,则应该找到屏幕尺寸,但这并不是一件容易的事,因为平板电脑的屏幕较小,而手机的屏幕较大.当然,仍然有可能获得屏幕尺寸.

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.

您可以尝试使用GSM功能执行某些操作.但是同样,也有例外,例如可以打电话的平板电脑.

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:

  • 您需要获取设备浏览器的useragent字符串.我猜用哪一种是不合逻辑的
  • 可以更改用户代理字符串,就像某些人不希望使用移动网站一样,因此他们可以更改其代理字符串.那会影响您的行为,这很奇怪.

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

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