What APIs Are Used to Draw Over Other Apps (Like Facebook'S Chat Heads)

What APIs are used to draw over other apps (like Facebook's Chat Heads)?

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() {
super.onCreate();

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.android_head);

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);

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

windowManager.addView(chatHead, params);
}

@Override
public void onDestroy() {
super.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.

Can you draw over Facebook chat heads on Android?

I fixed it by setting the type in the layout params to TYPE_APPLICATION_OVERLAY for Oreo and later and to TYPE_SYSTEM_ALERT for pre-Oreo.

How is Facebook Chat Heads implemented?

Search for permission android.permission.SYSTEM_ALERT_WINDOW and WindowManager.LayoutParams.TYPE_SYSTEM_ALERT.

See this blogpost by Daniel Jankowski and his WindowHead sample on GitHub.

In addition to the duplicate answer already listed, also see:

  • Having application running above other app
  • Disappearing facebook chat heads


Related Topics



Leave a reply



Submit