Android informations about floating overlays/elements over other apps
Asked Answered
A

1

6

I'm looking for some informations about floating overlays Not overlays of a mapView but overlays floating over other applications.

For example those applications are doing what I'm looking for :

https://play.google.com/store/apps/details?id=com.pvy.batterybar

https://play.google.com/store/apps/details?id=ds.cpuoverlay

They are displaying elements in front of the screen even if we are not in the application

I tried some searches but I didn't found anything.

Does someone knows where to find some API documentation, a tutorial link, a piece of code ...

Thanks

Afterheat answered 24/5, 2012 at 10:19 Comment(1)
I found also : play.google.com/store/apps/… which detects tap and launch some actionsAfterheat
T
0

In order to do that, you will need a permission "android.permission.SYSTEM_ALERT_WINDOW". After adding the permission in your manifest file, do something like this:

final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.my_floating_view);
final ViewGroup parent=(ViewGroup)view.getParent();
parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=view.getLayoutParams().width;
param.height=view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);

Also, I believe this is how Facebook chat heads are done. Hope that helped!

Towns answered 19/4, 2013 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.