how to display dialog builder in front of floating window - android

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"/>

Related

Android Soft Keyboard is not working properly with Accessibility Service and WindowManager

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.

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.

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.

Align an activity as dialog on top left

i know this question was asked for aligning a dialog on the left,
but here i'm using an activity with a
android:theme="#android:style/Theme.Dialog" and the problem is that it's display at the center of the screen and i want to display on the top left corner.
is there any way to do so ?
i have tried using the android:layout_gravity="top|left" on my concerned activity .xml but that doesn't work.
Thank you for your help
Try this on your onCreate of dialog activity
WindowManager.LayoutParams wmlp = getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
Hope it helps.

Full screen overlay in ICS

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

Categories

Resources