Overlay Android Application Over The Country (HUD)

I want to impose a view on my entire application, including all the actions. Think of it as a HUD (Head Up Display) on my application. The application has several actions, including tab activity, and the HUD does not interact with the user in any way; it simply displays information, allowing the user to interact with the application as usual. I want this HUD for debugging, so I (and others) can track application activity and indicate when the phone is not connected to the debugging machine (field testing).

How do I add this view?

I tried using WindowManager.addView () as follows:

WindowManager.LayoutParams lp = new WindowManager.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); windowManager.addView(hudView, lp); 

But the HUD does not seem to persist in the foreground, when I start new actions, it just disappears.

+4
source share
2 answers

I know this is an old question, but I thought I would answer anyway, since it helped me. I tried to run a HUD in an openGL game, and this works great for this.

Since you already have a HUD display with the window manager, all you need to do to keep things consistent is call windowManager.addView(hudView, lp); in every onResume() action. Not sure what the memory implications are (i.e., this is the view that is deleted when the window manager removes it from the screen when activity is switched), but at least it will support HUD throughout the application.

+1
source

I read that you stopped working with Android, but perhaps for further readers:

You missed the WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, flag. Best implemented as an overpriced service. Do not name it in every activity in onResume.

0
source

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


All Articles