Android service to judge the system full screen

Source: Internet
Author: User

1. Empty layout

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "Vertical" ></LinearLayout>

2. Define layout variables in Java

Mfullscreencheckview = (linearlayout) inflater.inflate (r.layout.full_screen_layout, NULL);

3. Set the global Layout Listener

private void Createfullscreencheckview () {SECLOG.E (TAG, "Createfloatview"); Windowmanager.layoutparams layoutparams = new Windowmanager.layoutparams (); layoutparams.type = LayoutParams.TYPE_ Phone;layoutparams.format = Pixelformat.transparent;layoutparams.flags = layoutparams.flag_not_focusable; layoutparams.gravity = Gravity.left | Gravity.top;layoutparams.width = 1;layoutparams.height = layoutparams.match_parent; Mfullscreencheckview.getviewtreeobserver (). Addongloballayoutlistener (New Ongloballayoutlistener () {@SuppressLint ("Newapi") @Overridepublic void Ongloballayout () {displaymetrics dm = new Displaymetrics (); Mwindowmanager.getdefaultdisplay (). Getmetrics (DM); int viewheight = Mfullscreencheckview.getheight (); if (viewHeight = = Dm.widthpixels | | Viewheight = = dm.heightpixels) {Bisfullscreen = true;} Else{bisfullscreen = false;}}); Mwindowmanager.addview (Mfullscreencheckview, layoutparams);} 

Reference:

1. Https://stackoverflow.com/questions/22894108/detect-full-screen-in-android-from-service

2. https://stackoverflow.com/questions/18551135/ receiving-hidden-status-bar-entering-a-full-screen-activity-event-on-a-service/19201933#19201933

Android service to judge the system full screen

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.