码迷,mamicode.com
首页 > 移动开发 > 详细

Android Service中判断系统全屏

时间:2015-01-31 12:32:00      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

1. 空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. java中定义layout变量

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

3. 设置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")
			@Override
			public 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);
	}

参考:

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中判断系统全屏

标签:

原文地址:http://blog.csdn.net/torvalbill/article/details/43339393

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!