Recently solved this problem: how to distinguish between using a mobile phone or tablet.
Find the following solutions online:
How to use the program to determine whether the user is using a mobile phone or tablet computer. Displaymetrics DM;
DM = new Displaymetrics ();
This.getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
Get the width of the screen
int intscreenx = Dm.widthpixels;
Get high on the screen
int intscreeny = Dm.heightpixels;
This only gets the resolution, the pixel
Like some cell phones, there's 960 *640 now.
Some of the 7-inch plates are 1024*600.
And behind the new phone like HTC, the resolution is already 1000.
Resolution This road is out of line.
The system version is not going to work.
There's some 2.3 of the tablet.
4.0 of Samsung's phones are out right now.
The required function is actually very simple, is to open a Web page, if it is a mobile phone, open the Mini, such as WAP
If it's a tablet, it's probably open WWW.
In fact, the function to be confused simple, judging the actual screen size (inches), 7 inch and above (in fact, >6 can, see the individual) is considered to be flat, directly open the big page ~ ~ ~
Get the long width, the Pythagorean theorem gets diagonal, ok~~~
Displaymetrics DM;
DM = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
Get the width of the screen (pixel)
int screenX = dm.widthpixels;
Get the high (pixel)
int screenY = dm.heightpixels of the screen;
Pixel dots per inch
int dpi = dm.densitydpi;
Get the width of the screen (inch)
float a = screenx/dpi;
Get the screen high (inch)
float B = screeny/dpi;
Pythagorean
Double screenin = math.sqrt ((A * a) + (b * b));
The following parameters are obtained by measuring several devices around them:
Huawei MediaPad x=800 y=1216 dpi=213 a=3 b=5 screenin=5.8
Xiaomi 1s x=480 y=850 dpi=240 a=2 b=3 screenin=3.6
Xiaomi 2 x=720 y=1280 dpi=320 a=2 b=4 screenin=4.47
Motorola MZ606 x=800 y=1232 dpi=160 a=5 b=7 screenin=8.6
I think Screenin is equal to 5.
Have a chance to take a Samsung flatbed test