Daniel A. White Daniel A. White - 1 year ago 48
Android Question

What APIs in Android is Facebook using to create Chat Heads?

How does Facebook create the Chat Heads on Android? What is the API to create the floating views on top of all other views?

Answer Source

This one:

Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. Very few applications should use this permission; these windows are intended for system-level interaction with the user.

Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"

//EDIT: The full code here:

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() {

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    chatHead = new ImageView(this);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(

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

    windowManager.addView(chatHead, params);

  public void onDestroy() {
    if (chatHead != null) windowManager.removeView(chatHead);

Don't forget to start the service somehow:

startService(new Intent(context, ChatHeadService.class));

.. And add this service to your Manifest ;-)