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
Auto Scale Textview Text to Fit Within Bounds
How to Dynamically Add Suggestions to Autocompletetextview With Preserving Character Status
How to Add Parameters to Httpurlconnection Using Post Using Namevaluepair
Replace Fragment Inside a Viewpager
How to Change the Background Color of the Actionbar of an Actionbaractivity Using Xml
How to Get Zoom Functionality For Images
Android - Dynamically Add Views into View
Filter Logcat to Get Only the Messages from My Application in Android
How to Start an Application Using Android Adb Tools
Android - Listen For Incoming Sms Messages
Getting an Issue While Checking the Dynamically Generated Checkbox Through List View
Close Application and Launch Home Screen on Android
How to Start a Service When .Apk Is Installed For the First Time
All Com.Android.Support Libraries Must Use the Exact Same Version Specification