我在使用下面的代码时正在访问窗口管理器。
public class MyWindowManager {
private WindowManager windowManager;
private WindowManager.LayoutParams windowManagerParams;
private View view;
private int windowManagerLastX, windowManagerLastY, windowManagerFirstX, windowManagerFirstY;
boolean touchConsumeByMove = false;
private static MyWindowManager myWindowManager;
private MyWindowManager(){}
public synchronized static MyWindowManager getInstance() {
if (myWindowManager == null)
myWindowManager = new MyWindowManager();
return myWindowManager;
}
public void getWindowManagerPopUp(Context context) {
windowManager = (WindowManager) MyApplicationContext.getAppContext().getSystemService(Context.WINDOW_SERVICE);
windowManagerParams = new android.view.WindowManager.LayoutParams(
android.view.WindowManager.LayoutParams.MATCH_PARENT,
android.view.WindowManager.LayoutParams.MATCH_PARENT, android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY | android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSPARENT);
LayoutInflater layoutInflater = (LayoutInflater) MyApplicationContext.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.dialogue_activity, null);
view.setOnTouchListener(recButtonOnTouchListener);
windowManagerParams.height = (int) DensitiesConversion.dpToPx(MyApplicationContext.getAppContext(), 230);
windowManagerParams.gravity = Gravity.CENTER;
windowManagerParams.format = PixelFormat.TRANSLUCENT;
windowManager.addView(view, windowManagerParams);
}
}。 我找不到为什么窗口管理器无法启动的问题。场景是当应用程序收到来电时,广泛的广播接收者触发。然后调用webservice以获得响应。到这里一切都工作正常,但是当收到响应后,我带来了一个没有来的窗口管理器。下面是我用来获取窗口管理器的代码。
在成功响应Web服务时,我正在使用以下代码。
myWindowManager.getWindowManagerPopUp(this);
然后我在IntentService中调用Web服务,并在IntentService的构造函数内部调用myWindowManager,如下面的代码片段所示。
public FindNumberService() {
super("FindNumberService");
myWindowManager = MyWindowManager.getInstance();
}
任何帮助。