0

I created a small service, just like here:

Facebook Chatheads Service

public class ChatHeadService extends Service {

  private WindowManager windowManager;
  private ImageView chatHead;

  @Override public IBinder onBind(Intent intent) {
  // Not used
  return null;
  }

  @Override public void onCreate() {
  super.onCreate();

  windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

  chatHead = new ImageView(this);
  chatHead.setImageResource(R.drawable.android_head);

  WindowManager.LayoutParams params = new WindowManager.LayoutParams(
      WindowManager.LayoutParams.MATCH_PARENT,
      WindowManager.LayoutParams.MATCH_PARENT,
      WindowManager.LayoutParams.TYPE_PHONE,
      WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
      PixelFormat.TRANSLUCENT);

  params.gravity = Gravity.TOP | Gravity.LEFT;
  params.x = 0;
  params.y = 100;

  windowManager.addView(chatHead, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (chatHead != null) windowManager.removeView(chatHead);
  }
}

Only difference is that my ImageView is MATCH_PARENT on width and height, the image inside is 99% transparent.

Everything works fine, but I can not touch, swipe or anything else when the service runs. I want the ImageView to be totally hidden for any touch interaction with the user - like the ImageView is nothing else but a sticker on the glass.

I tried setClickable(true / false) and als to override onTouchEvent with returning true / false, but to no avail.

Any help here on how to accomplish this?

P.S.: I know this is no desired behavior of a serious app, but this is just meant to be a little joke app for me & my friends.

LilaQ
  • 349
  • 5
  • 19

1 Answers1

2

Okay, for anyone in the future wondering - changing my flags to

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
      WindowManager.LayoutParams.MATCH_PARENT,
      WindowManager.LayoutParams.MATCH_PARENT,
      WindowManager.LayoutParams.TYPE_PHONE,
      WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
      PixelFormat.TRANSLUCENT);

did the trick. The FLAG_NOT_TOUCHABLE will make the View totally irrelevant for any touch input. In my example I can cover my whole screen with a semi-transparent ImageView and still use my launcher etc. normally.

LilaQ
  • 349
  • 5
  • 19