Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to properly detect if an Android device is a phone or a tablet?

$
0
0

Hi, all.

Up until now, I was using the ScreenLayout to detect if an Android device is a phone or a tablet, to force the orientation to Portrait/Landscape. The problem with the code below is that, for devices such as the Google Pixel 2, it returns true for SizeLarge. Is there any bulletproof way to detect if a device can be classified as a tablet? I was thinking about using a ratio between the physical size of the screen and the DPI, but I feel that it still is prone to errors.
Thank you.

context = context ?? MainApplication.Context;
var screenLayout = context.Resources.Configuration.ScreenLayout & Android.Content.Res.ScreenLayout.SizeMask;
return screenLayout == Android.Content.Res.ScreenLayout.SizeLarge || screenLayout == Android.Content.Res.ScreenLayout.SizeXlarge;


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>