
package com.example.testwindow;import androID.app.Service;import androID.content.Context;import androID.content.Intent;import androID.graphics.color;import androID.graphics.PixelFormat;import androID.os.IBinder;import androID.util.Log;import androID.vIEw.Gravity;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.Window;import androID.vIEw.WindowManager;import androID.vIEw.WindowManager.LayoutParams;import com.androID.internal.policy.PolicyManager;public class WindowManagerService extends Service { private String TAG ="WindowManagerService"; private Context mContext; private WindowManager mWindowManager; private Window mWindow; @OverrIDe public voID onCreate() { super.onCreate(); Log.i(TAG,"onCreate vIEw"); this.mWindowManager = ((WindowManager) getSystemService("window")); mContext = this; } @OverrIDe public int onStartCommand(Intent intent,int flags,int startID) { int i = super.onStartCommand(intent,flags,startID); VIEw editwindow = LayoutInflater.from(mContext).inflate(R.layout.activity_main,null); mWindow = adDWindow(editwindow,LayoutParams.TYPE_PHONE); int msystemUIVisibility = mWindow.getDecorVIEw().getsystemUIVisibility(); mWindow.getDecorVIEw().setonsystemUIVisibilitychangelistener(new VIEw.OnsystemUIVisibilitychangelistener(){ @OverrIDe public voID onsystemUIVisibilityChange(int visibility) { Log.e(TAG,"systemUI onsystemUIVisibilityChange ="+visibility); } }); Log.e(TAG,"msystemUIVisibility ="+msystemUIVisibility); WindowManager.LayoutParams layoutParams = mWindow.getAttributes(); layoutParams.x = 0; layoutParams.y = 0; layoutParams.wIDth = 500; layoutParams.height = 600; layoutParams.gravity = Gravity.top | Gravity.left; layoutParams.hassystemUIListeners = true; layoutParams.setTitle("WindowManagerService"); mWindow.setAttributes(layoutParams); mWindowManager.updateVIEwLayout(mWindow.getDecorVIEw(),layoutParams); return i; } public WindowManager.LayoutParams createLayoutParams() { Log.i(TAG,"createLayoutParams"); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams( LayoutParams.TYPE_SYstem_ERROR,LayoutParams.FLAG_NOT_FOCUSABLE,PixelFormat.TRANSLUCENT); layoutParams.softinputMode = LayoutParams.soFT_input_ADJUST_PAN; layoutParams.setTitle(getClass().getname()); return layoutParams; } public Window adDWindow(VIEw paramVIEw,int wIDth,int height,int type) { Log.i(TAG,"adDWindow vIEw"); WindowManager.LayoutParams layoutParams = createLayoutParams(); Window localWindow = PolicyManager.makeNewWindow(this.mContext); if (localWindow != null) { localWindow.setwindowManager(this.mWindowManager,null,null); localWindow.requestFeature(Window.FEATURE_NO_Title); localWindow.setFlags(WindowManager.LayoutParams.FLAG_FulLSCREEN,WindowManager.LayoutParams.FLAG_FulLSCREEN); layoutParams.wIDth = wIDth; layoutParams.height = height; layoutParams.type = type; layoutParams.format= PixelFormat.transparent; layoutParams.flags = (LayoutParams.FLAG_NOT_FOCUSABLE | layoutParams.flags); localWindow.setAttributes(layoutParams); localWindow.setContentVIEw(paramVIEw); VIEw localVIEw = localWindow.getDecorVIEw(); if (localVIEw != null) { localVIEw.setVisibility(VIEw.VISIBLE); this.mWindowManager.addVIEw(localVIEw,layoutParams); } return localWindow; } return null; } @OverrIDe public IBinder onBind(Intent intent) { // Todo auto-generated method stub return null; } @OverrIDe public voID onDestroy() { if (mWindow != null) { mWindowManager.removeVIEw(mWindow.getDecorVIEw()); mWindow = null; } super.onDestroy(); }} 当我开始服务时,其他应用程序更改为FulLSCREEN,我无法获取日志“systemUI onsystemUIVisibilityChange =”
有人可以解释这种行为吗?为什么听不到改变?
解决方法 您可以在调用addVIEw之前尝试添加侦听器. 总结以上是内存溢出为你收集整理的View.OnSystemUiVisibilityChangeListener在Android服务中不起作用全部内容,希望文章能够帮你解决View.OnSystemUiVisibilityChangeListener在Android服务中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)