Android info on floating overlays / elements over other apps

I'm looking for information on floating overlays. Do not overlap with mapView, but overlap on top of other applications.

For example, these applications do 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 display elements in front of the screen, even if we are not in the application.

I tried some searches but found nothing.

Does anyone know where to find API documentation, a link to a tutorial, a piece of code ...

thanks

+6
source share
1 answer

To do this, you will need the permission " android.permission.SYSTEM_ALERT_WINDOW ". After adding permission to the manifest file, do the following:

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); 

In addition, I believe that this is the way Facebook chat chapters are done. Hope this helps!

0
source

Source: https://habr.com/ru/post/916541/


All Articles