Facebook chat like floating chat heads

Facebook recently released a new feature in Facebook Messenger in which the chat from person floats on screen instead of residing inside conventional application. This feature is very continent for multitasking as user can work and chat at the same time. Like you are using calculator and someone message you on facebook then this chat is shown over calculator like a floating bubble and you can reply to this chat by just by clicking the chat head and then resume your work after ward . So no app switching !!!

Chathead Basics :

At first it looks like some kind of transparent activity. But its not a transparent activity.

That means its a service running in background and controlling the view which is attached to window. As you probably know, an Activity has a Window instance. Dialogs also have their own dedicated Window. Even Services can have Window: InputMethodService uses a Window to receive touch events and draw a keyboard on top of another Window, and DreamService is used to create screensavers.

To open a new window in which you will draw the chathead, you need the SYSTEM_ALERT_WINDOW permission.

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

Preview:

 

 

chat_head_preview

 

Lets get Started :

1. Create new project :

Create a new project File -> New -> Android Project

 

2. Add a new service to project

Add a new class named ChatHeadService.java

3. Update activity_main.xml

Add following code to activity_main.xml. This will add buttons to control the visibility of the chathead.

4. Update manifest file

Update the manifest file by adding service to menifest along with permission for SYSTEM_ALERT_WINDOW

5. Build and Run

Now build and run the project to see the results

 

 

 

 

GuRu

Technology enthusiast. Loves to tinker with things. Always trying to create something wonderful using technology. Loves coding for Android, Raspberry pi, Arduino , Opencv and much more.

You may also like...