android_dev
android_dev

Reputation: 1477

is it possible to add a view to WindowManager in android TV

I have a requirement like i need to show some icon when my app was not running on foreground. For this i need to add the view to window manager. is it possible to add view to window manager in android tv.

this is the code i tried

   LayoutInflater inflater = LayoutInflater.from(getActivity());
        final View layout = inflater.inflate(R.layout.layout_show_on_top_of_view, null);

        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.gravity = Gravity.TOP | Gravity.LEFT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.type = WindowManager.LayoutParams.TYPE_TOAST;
        params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        params.format = PixelFormat.TRANSLUCENT;
        params.windowAnimations = 0;
        final WindowManager mWindowManager = (WindowManager)
                getActivity().getSystemService(Context.WINDOW_SERVICE);
        mWindowManager.addView(layout, params);
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mWindowManager.removeView(layout);
            }
        });

i tried different types too but it's not working.

Upvotes: 2

Views: 483

Answers (1)

shalafi
shalafi

Reputation: 3996

I think what you want to achieve can be done with a transparent Activity, check out this other question/answer: Is it possible to draw overlay over any screen using 3rd party app in android TV?

Upvotes: 1

Related Questions