Android - how to find out from within running app if device it is running on is phone or tablet [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:02:27

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/4947699/android-how-to-find-out-from-within-running-app-if-device-it-is-running-on-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!