Android Service determines the full screen of the system, androidservice

Source: Internet
Author: User

Android Service determines the full screen of the system, androidservice

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:orientation="vertical" ></LinearLayout>

2. Define the layout variable in java

mFullScreenCheckView = (LinearLayout) inflater.inflate(R.layout.full_screen_layout, null);

3. Set 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);}

Refer:

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

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.