Android: How to draw free on top of anything (any activity)

14,245

Solution 1

Take a look at this cool article, I think that's exactly what you want :

http://www.piwai.info/chatheads-basics

In short : you want to add this permission to your manifest :

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

For api >= 23, you'll need to request the runtime permission Settings.ACTION_MANAGE_OVERLAY_PERMISSION

Then in a service, get the window manager

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

and add your views with the addView method

Solution 2

Take a look at WindowManager. You can do something like (WindowManager)mContext.getSystemService("window"); if you want to get the root view and use the method addView(view, params) if you want to add a view.

Share:
14,245

Related videos on Youtube

Allahjane
Author by

Allahjane

Updated on October 12, 2022

Comments

  • Allahjane
    Allahjane over 1 year

    How do you draw a view on top of all other activities regardless of what they are showing and without using transparent activities or consuming its touch events.

    Its like to display a custom icon on the screen on top of all other apps that reacts when you touch it but you can still touch the other views on the screen.

    Example: facebook chat heads that displays a dragable and clickable icon on screen regardless of what you are doing whether you are on home screen or app menus or any app. Still you can click the chat head icon and background app elements seperately

    How to do anything like that?

  • Allahjane
    Allahjane almost 11 years
    relevant but I needed more details ! thanks for your input anyway
  • arekolek
    arekolek over 8 years
  • SlashG
    SlashG over 7 years
    This works for me on <23 devices, not on my 23 device. I'm targeting 22. Do I need to upgrade to 23+ and implement runtime permissions throughout to achieve this?
  • Hitesh Dhamshaniya
    Hitesh Dhamshaniya over 7 years
    piwai.info/chatheads-basics your provided link is expired now, there is error Page not found :(, could you update if its relocation anywhere.