Is there a way to check if the user is using a tablet or a phone? I've got problems with my tilt function and my new tablet (Transformer)
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I know this is not directly an answer to your question, but other answers here give a good idea of how to identify screen size. You wrote in your question that you got problems with the tilting and this just happened to me as well.
If you run the gyroscope (or rotation sensor) on a smartphone the x- and y-axis can be differently defined than on a tablet, according to the default orientation of that device (e.g. Samsung GS2 is default portrait, Samsung GT-7310 is default landscape, new Google Nexus 7 is default portrait, although it is a tablet!).
Now if you want to use Gyroscope you might end up with a working solution for smartphones, but axis-confusion on some tablets or the other way round.
If you use one of the solutions from above to only go for screen-size and then apply
to flip the axis if it has a large or xlarge screen-size this might work in 90% of the cases but for example on the Nexus 7 it will cause troubles (because it has default portrait orientation and a large screen-size).
The simplest way to fix this is provided in the RotationVectorSample that ships with the API demos by setting the sceenOrientation to
nosensor
in your manifest:As it has been mentioned before, you do not want to check whether the device is a tablet or a phone but you want to know about the features of the device,
Most of the time, the difference between a tablet and a phone is the screen size which is why you want to use different layout files. These files are stored in the
res/layout-<qualifiers>
directories. You can create an XML file in the directoyres/values-<same qualifiers>
for each of your layouts and put an int/bool/string resource into it to distinguish between the layouts you use.Example:
File
res/values/screen.xml
(assumingres/layout/
contains your layout files for handsets)File
res/values-sw600dp/screen.xml
(assumingres/layout-sw600dp/
contains your layout files for small tablets like the Nexus 7)File
res/values-sw720dp/screen.xml
(assumingres/layout-sw720dp/
contains your layout files for large tablets like the Nexus 10):Now the screen type is accessible via the
R.string.screen_type
constant.I think a tablet has a min and max 600 px width and height,
so need to know the screen density and the height/width in dp,
to retrieve the value :
For me the distinction between phone and tablet is not size of device and/or pixel density, which will change with technology and taste, but rather the screen ratio. If I'm displaying a screen of text I need to know if, say, 15 long lines are needed (phone) vs 20 shorter lines (tablet). For my game I use the following for a ballpark estimation of the rectangle my software will be dealing with:
In the Google IOSched 2017 app source code, the following method is used: