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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要因屏幕尺寸而有所不同,则应该找到屏幕尺寸,但这并不容易,因为平板电脑有小屏幕,手机也有大屏幕。不过,当然可以获得屏幕尺寸。
您可以尝试使用 GSM 功能做一些事情。但同样,也有例外,比如可以调用的平板电脑。
我建议不要进行这种区分,并根据您的需要来定义它。屏幕尺寸、功能等。您可能会得到由“电话”和“桌子”组成的组,但您将更好地了解您的组是什么样的。
我仍然不确定如何定义“平板电脑”,并且您尝试的所有内容都需要该定义,但是如果您看一下 此链接,您可以看到,可能(快速阅读)那些认为自己是平板电脑的东西不会在其中识别自己作为移动设备的用户代理字符串。
但是:
最后,我认为您需要定义平板电脑是什么,然后检查它!
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:
In the end I think you need to define what a tablet is, and then check for that!