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.
Related
So, finally here I'm, after searching the Google and SO for this perticular problem which made me crasy from past 3 days. A lot of answers are out there but it seems that neither of them seems to solve this specific issue. Here is what I have found so far,
Show keyboard automatically
Android soft keyboard not working
How to hide and show Android Soft keyboard from an Accessibility Service
Window manager blocking keyboard for apps underneath floating chat head
Android: show soft keyboard automatically when focus is on an EditText
Android - Keyboard not appearing in floating window
What I want to acheive
I want to open a screen with EditText in it from AccessibilityService (This part is done).
Open keyboard and type text in the EditText.
Take the input text from EditText (with a button click), and send it to the EditText of Messaging App, and then perform a click event on send button in Messaging App. This all will be done using AccessibilityService and not by the user.
The overlayed screen should be removed when user expand the notification_panel or press the Back, Home or Recents button from the navigation area.
The Problem
Im unable to handle keyboard and its input on an EditText inflated using WindowManager in an AccessibilityService.
Scenarios/use cases
Scenario 1 (Image 1)
-> Inflated the view with window type TYPE_APPLICATION_OVERLAY and window flag FLAG_NOT_FOCUSABLE.
Able to acheive
I can listen to all events in AccessibilityService.
I can remove the overlayed window when notification_panel expands.
I can listen to navigation buttons, and handle the code accrodingly.
Unable to acheive
Unable to show keyboard by clicking on EditText or programatically.
what I have tried so far
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
chattingLayoutParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
} else {
chattingLayoutParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
}
and this (but not working)
val imm: InputMethodManager =
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(someEditText, InputMethodManager.SHOW_IMPLICIT)
Scenario 2 (Image 2)
-> Inflated the view with window type TYPE_APPLICATION_OVERLAY and window flag FLAG_NOT_TOUCH_MODEL.
Able to acheive
Show keyboard and type text.
Unable to acheive
Can not trigger events in the SccessibilityService.
Unable to trigger the notification_panel changes to remove overlayed window.
Unable to trigger navigation buttons (back, home, recents) actions to remove overlayed window.
What i have tried so far
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
chattingLayoutParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT
)
} else {
chattingLayoutParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT
)
}
AccessibilityService Config.xml file
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken"
android:accessibilityFlags="flagReportViewIds"
android:canRetrieveWindowContent="true"
android:notificationTimeout="100" />
I hope the problem is clear, please forgive for any inconvenience.
This is because of when you overlay screen the input manager required to meets the opacity condition not exceed InputManager.getMaximumObscuringOpacityForTouch() which is currently 0.8f.
Just set
chattingLayoutParams.alpha = 0.8f to fix it.
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"/>
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.
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.
I have a full screen program that overlays the status bar so that you can see it but cannot click on it (like the lock screen). When I run my program in Ice Cream Sandwich my app drops down below the status bar (allowing it to be touched). How can I get it to work again in ICS?
I use the following code:
final WindowManager.LayoutParams mOverLayParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
I know only solution with replacing TYPE_SYSTEM_ALERT to TYPE_SYSTEM_OVERLAY. But in this way your window will not receive touch events.
Try the FLAG_FULLSCREEN.
Documentation is here: http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN
Example:
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);