Home > Mobile >  Why the WindowManager removeView cannot be removed
Why the WindowManager removeView cannot be removed

Time:09-16

My small white found in the learning process to monitor phone calls the popup window cannot be removed,
When can pop-up window, but window cannot be removed after hanging up, use removeViewImmediate () also not line,
Really puzzled, please help, thank! The code is as follows:
Public class MyReceiver extends BroadcastReceiver {
Public final String TAG="MyReceiver";
Private WindowManager mWinMgr;
Private TextView mTxtView;
Public MyReceiver () {
}
@ Override
Public void onReceive (Context Context, Intent Intent) {
String action=intent.getAction();
If (intent. GetAction (). The equals (TelephonyManager. ACTION_PHONE_STATE_CHANGED)) {
String phoneNumber=intent. GetStringExtra (TelephonyManager. EXTRA_INCOMING_NUMBER);
TelephonyManager telephony=(TelephonyManager) context. GetSystemService (context. TELEPHONY_SERVICE);
Int state=a telephony. GetCallState ();
The e (TAG, "state=" + state + ", phoneNumber="+ phoneNumber);
The switch (state) {
Case TelephonyManager. CALL_STATE_RINGING:
The e (TAG, "CALL_STATE_RINGING=" + state);
MWinMgr=(WindowManager) context. GetApplicationContext () getSystemService (context. WINDOW_SERVICE);
WindowManager. LayoutParams params=new WindowManager. LayoutParams ();
Params. Type=WindowManager. LayoutParams. TYPE_SYSTEM_OVERLAY;
Params. Flags=WindowManager. LayoutParams. FLAG_NOT_TOUCH_MODAL;
Params. Flags |=WindowManager. LayoutParams. FLAG_NOT_FOCUSABLE;
Params. Width=WindowManager. LayoutParams. MATCH_PARENT;
Params. Height=WindowManager. LayoutParams. WRAP_CONTENT;

Params. Gravity=gravity. TOP;
Params. Format=PixelFormat. RGBA_8888;
MTxtView=new TextView (context);
MTxtView. SetLayoutParams (new ViewGroup. LayoutParams (WindowManager. LayoutParams. MATCH_PARENT, WindowManager. LayoutParams. WRAP_CONTENT));


MTxtView. SetText (" caller id: "+ phoneNumber);
MTxtView. SetTextColor (0 XFFFFFFFF);
MWinMgr. AddView (mTxtView params);
break;
Case TelephonyManager. CALL_STATE_OFFHOOK:
If (mWinMgr!=null) {
MWinMgr. RemoveView (mTxtView);
}
break;
Case TelephonyManager. CALL_STATE_IDLE:
If (mWinMgr!=null) {
MWinMgr. RemoveView (mTxtView);
}
break;
Default:
If (mWinMgr!=null) {
MWinMgr. RemoveView (mTxtView);
break;
}
}
}
}

CodePudding user response:

Through other ways, solve the,
  • Related