How to add non-touchable view with WindowManager - android

I'm trying to add a non-clickable view, which will pass all clicks through it. I'm using the next code
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
But it doesn't works and I still can't find the correct combination. Could anyone please provide correct solution? Thanks a lot.

Related

how to display dialog builder in front of floating window

Hi....
I have an activity and a service in which in this service I am running a
windowmanager dialog (floating window)
Purpose of this is that.
I want to display this window every activity I visit so this floating window can also me minimize just like facebook messager except fb messenger is another application from facebook
then there are scenario that I want to display a dialog builder in my app my the problem is that since I am using floating window the dialog I display wont display in front of floating instead it just display at the back since I know floating window is also a dialog and my dialog display at the back of floating window,
my question is that is there any way to display my dialog in front of floating window?
I also tried displaying another floating window it's works but it will cause a lot of problem also
thanks for the help in future!
You can use WindowManager. WindowManager
For example, you can write code. Like this,
View v; // your dialog view
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,0,0,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP;
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(v, params);
Maybe you need permission,
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Why screen SYSTEM_ALERT_WINDOW enable cancel button and disable install button when apk install?

Please help and clarify me, why screen SYSTEM_ALERT_WINDOW enable cancel button and disable install button when apk install??
windowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
This is my code in Activity.
This is called tap-jacking protection, and is designed to prevent misleading the user into thinking the install button was something else (for example, by overlaying the bottom bar and switching the labels around), and passing the click through.

Overlay view added by Window Manager hides keyboard (Android)

I added a view to the Window Manager, an overlay button wich I can drag arround, but at the time that any kind of text input is needed, the keyboard just doesn't pop up like it used to be. This only works when I remove that view. It's a button added by a service with the following LayoutParams :
params = new WindowManager.LayoutParams(
button_size, button_size,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
, PixelFormat.TRANSPARENT);
params.gravity = Gravity.LEFT | Gravity.TOP;
I did some research and I also tried to add this to the Android Manifest:
android:windowSoftInputMode="stateVisible|adjustResize"
But this didn't work either.
Since I didn't find any related questions/answers, can someone help me?
Thank you in advance!
I got it by adding
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
to the LayoutParams flags.
This worked for me :
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PRIORITY_PHONE,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
PixelFormat.TRANSLUCENT);
This put the added view behind the keyboard.

WindowManager.addView ontop(overlay) of soft key OR nav bar

I saw an app that overlays whole screen including nav bar (or soft-key that has back, home, etc.) today. it's CF.Lumen(requires android 4.4+) by chainfire.
I just remembered this is NOT POSSIBLE on general approach and many SO answers told me. So I looked down smali codes from Lumens apk(sorry chainfire), found 0x7d6 as type specifier, which is TYPE_SYSTEM_OVERLAY.
In general, this makes a view overlays on top of lock screen. It looks good however it won't overlays nav bar area. even on lock screen.
I did replacing MATCH_PARENT to 9999 but it still won't overlays nav bar area.
I looked down the source code of Android, found interesting that has more types undocumented.
FIRST_SYSTEM_WINDOW = 2000;
TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;
TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;
I applied these to my app but got crashe says permission denied. It requires INTERNAL_SYSTEM_WINDOW OR something more undocumented than SYSTEM_ALERT_WINDOW. those permissions are granted for system apps only.
here's my code to add a view fills whole screen except nav bar area.
What should I do to acomplish it?(make overlay including nav bar area)
final WindowManager.LayoutParams paramsRL = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
windowManager.addView(view_floating, paramsRL);
Here's a small example which works:
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(Color.BLACK);
frameLayout.setAlpha(0.5f);
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
| WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT);
//make sure height includes the nav bar size (get the dimension of whole screen)
params.height = screenHeight;
params.width = screenWidth;
windowManager.addView(frameLayout, params);
//add your view to this frameLayout
frameLayout.addView(....);
Three key things here are:
TYPE_SYSTEM_OVERLAY (or any similar types) which can show content over the whole screen.
FLAG_LAYOUT_NO_LIMITS which allows us to go over the normal size allowed.
Setting the extra height required to be covered behind soft keys. The main problem was when we set the parameters to match_parent, it sets to the height of screen minus the nav bar I suppose. Setting the extra height solves the issue.
Don not use WindowManager.LayoutParams.FLAG_NOT_FOCUSABLEļ¼Œ this flag will make navigation bar always show. I don't kown why.

How to overlay status bar and navigation bar from a Service? (android 4.4)

android 4.4
I have a Service which is launched by Application (NOT an Activity).
When required, the Service needs to overlay the taskbar and navigation bar with a view.
How do I do it?
I tried
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.OPAQUE);
rootView = // inflate layout from xml file
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.addView(rootView, params);
This goes behind the taskbar and does not overlay it.
The android documentation https://developer.android.com/training/system-ui/navigation.html
requires using a DecorView obtained from getWindow().
My code will not compile since getWindow() does not exist.
How to overlay status bar and navigation bar from a Service? (android 4.4)
Use WindowManager.LayoutParams.TYPE_BOOT_PROGRESS

Categories

Resources