[Android Q & A] How do I obtain the cell phone screen size?

Source: Internet
Author: User

This question is not complex, but there are a lot of people asking, so I should concentrate on answering it.

Starting from Android 3.2 (API Level 13), use the following method in the activity to obtain the screen size (in pixels ):

 
Display display = getwindowmanager (). getdefaultdisplay ();//Activity # getwindowmanager ()Point size =NewPoint (); display. getsize (size );IntWidth =Size. X;IntHeight = size. Y;

IfCodeInstead of writing in the activity, use the following method (obtain the Display object through window_service ):

Windowmanager WM =(Windowmanager) CTX. getsystemservice (context. window_service); display=WM. getdefadisplay display (); display. getsize (size );IntWidth =Size. X;IntHeight = size. Y;

If the Android version3.2 or lessBecause the Display object does not have the getsize () method, use the following method to obtain the screen size:

 
Display display =Getwindowmanager (). getdefaultdisplay ();IntWidth = display. getwidth ();IntHeight = display. getheight ();

Finally, the android system version and API level table are provided:

Platform version API level Version_code Notes
For Android 4.2 17 Jelly_bean_mr1  
Android 4.1, 4.1.1 16 Jelly_bean Platform highlights
Android 4.0.3, 4.0.4 15 Ice_cream_sandwich_mr1 Platform highlights
Android 4.0, 4.0.1, 4.0.2 14 Ice_cream_sandwich
For Android 3.2 13 Honeycomb_mr2
Android 3.1.x 12 Honeycomb_mr1 Platform highlights
Android 3.0.x 11 Honeycomb Platform highlights
Android 2.3.4
Android 2.3.3
10 Gingerbread_mr1 Platform
Highlights
Android 2.3.2
Android 2.3.1
Android
2.3
9 Gingerbread
Android 2.2.x 8 Froyo Platform highlights
Android 2.1.x 7 Eclair_mr1 Platform
Highlights
Android 2.0.1 6 Eclair_0_1
For Android 2.0 5 Eclair
For Android 1.6 4 Donut Platform highlights
For Android 1.5 3 Cupcake Platform highlights
For Android 1.1 2 Base_1_1  
For Android 1.0 1 Base  

 

References

Display | Android Developers

Android: How to Get screen dimensions

What is API level?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.