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

yuuzhantar
  • 61
  • 3
  • I found also : https://play.google.com/store/apps/details?id=com.rootuninstaller.rambooster which detects tap and launch some actions – yuuzhantar May 24 '12 at 10:20

1 Answers1

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!

Srichand Yella
  • 4,218
  • 2
  • 23
  • 24