26

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
  • 1,920
  • 3
  • 24
  • 42

2 Answers2

34

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

Community
  • 1
  • 1
Fredszaq
  • 3,091
  • 1
  • 18
  • 20
  • Exactly ! that's the answer I needed Thanks a TON mate! – Allahjane May 16 '13 at 07:11
  • See http://stackoverflow.com/help/how-to-answer and http://meta.stackexchange.com/a/8259/307923 – arekolek Nov 29 '15 at 21:27
  • 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? – SlashG Sep 09 '16 at 11:50
  • http://www.piwai.info/chatheads-basics/ your provided link is expired now, there is error Page not found :(, could you update if its relocation anywhere. – Hitesh Dhamshaniya Jan 17 '17 at 07:01
3

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.

bogdan
  • 782
  • 3
  • 7