Android-如何从正在运行的应用程序中查找正在运行的设备是手机还是平板电脑 [英] Android - how to find out from within running app if device it is running on is phone or tablet

查看:81
本文介绍了Android-如何从正在运行的应用程序中查找正在运行的设备是手机还是平板电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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!

这篇关于Android-如何从正在运行的应用程序中查找正在运行的设备是手机还是平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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