Reputation: 578
I want to remove TYPE_SYSTEM_OVERLAY view which is added on Android service it is possible. my service is..
OverlayService Service
public class OverlayService extends Service {
WindowManager wm;
View myView;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0, 0,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
PixelFormat.RGBA_8888);
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
myView = inflater.inflate(R.layout.activity_charging, null);
myView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println("==== Remove View ");
wm.removeView(myView);
return false;
}
});
wm.addView(myView, params);
super.onCreate();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical">
<Button
android:id="@+id/btnRemoveView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text="Remove View" />
</RelativeLayout>
as per my above code the view is added on screen when app is call but in that button click is not working,what i want..I want to remove that created view on button click , if it is possible to remove custom TYPE_SYSTEM_OVERLAY then how ..? help me..
Thanks.
Upvotes: 2
Views: 1043
Reputation: 130
You have probably fixed it or moved on but just in case:
The reason its not responding is because I could not get TYPE_SYSTEM_OVERLAY
to respond to touch events. The way to do this is use the type TYPE_SYSTEM_ALERT
and to use the flags:
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Then it should respond correctly with the rest of your code.
Upvotes: 2