I have an application that has a transparent background activity and with only a few buttons. When I switch to my application from another (using the button to switch between applications) I would like to keep the previous app visible in the background. Problem is that switching active app minimizes the previous one and is no longer visible.
Is it possible to do that? I realized that in the Play Store when I throw my request the background remains the Play Store.
Please get me out of my doubt if this is possible or not.
Reality: point 4 return home screen
expectation
does this solve your riddle?
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View oView = layoutInflater.inflate(R.layout.activity_transperant, null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(oView, params);
Related
I am trying to click the force stop button using the accessibility service.when i find the FORCE STOP button i click it using:
childNodeView.performAction(AccessibilityNodeInfo.ACTION_CLICK);
this is successful in ordinary scenario, however when I try to hide the process from the user using a window manager overlay the click doesn't work. This makes since maybe because there is a screen over the button I am trying to click, however there are several applications on the play store that have the described functionality with a window overlay
these are my window manager params:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.START;
oneTapProgressView = new OneTapProgressView(this);
windowManager.addView(oneTapProgressView, params);
Note: I run this from a different service and not from the accessibility service
How do I perform the click with the window overlay?
I believe this is related to the overlay type. Specifically TYPE_PHONE. Phone overlays have special mechanisms to trap events so that users don't accidentally touch buttons with their cheek why talking on the phone.
You should try a different type. For Android O Try:
TYPE_APPLICATION_OVERLAY
For prior operating systems you want:
TYPE_SYSTEM_ALERT
Both of these will require the following permission:
SYSTEM_ALERT_WINDOW
Also, the following flags may be useful if the above alone doesn't fix it:
FLAG_NOT_FOCUSABLE
I have a service in which, when the user shakes his/her phone, shows a full screen overlay window. I'm using this code to get it done:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mOverlayView = inflater.inflate(R.layout.overlay, null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |WindowManager.LayoutParams.FLAG_FULLSCREEN,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mOverlayView, params);
It fills up the whole screen, EXCEPT for the navigation bar. Is there a way I can hide the navigation in my service that displays the overlay?
Note that my app is running in the background. The user may be running any other app in the foreground, and I want to show my full screen overlay window even if my main activity is not running.
All examples I could find online all seem to require an activity running...
Thanks for any help!
I've been trying for weeks to find a proper solution to this problem, but I still couldn't find anything.
Basically, what I'm trying to do is to create an alert dialog box from a running service (that monitors for some event). The alert dialog should always appear on top of everything else, even if the phone is locked. I'm looking for something similar to what happens when someone calls you, or when an alarm clock goes off.
The best solution I've found was the following:
WindowManager mWindowManager = (WindowManager)
mContext.getSystemService(Context.WINDOW_SERVICE);
LayoutInflater layoutInflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = layoutInflater.inflate(R.layout.layout_alert, null);
mLayoutParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.RGBA_8888);
mWindowManager.addView(mView, mLayoutParams);
And in the manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
The problem is that if I use the TYPE_SYSTEM_ALERT, then the dialog is always shown as I wanted, but I cannot receive any touch events on the buttons I have in the view. On the other hand, if I use TYPE_PRIORITY_PHONE, then I do receive all touch events - but the alert isn't shown above the lock screen.
My activity creates a system overlay view on the click of a button. I expect this view to remain visible over everything else till i close it on another button click in the activity.
The problem is Android automatically kills that view in a few seconds if i open couple of other applications. I know this is the expected behaviour of Android to manage it's resources. But is there a way to tell Android not to close this view? I tried creating the overlay in an IntentService, but it made no difference.
View creation code :
mFrameLayout = new FrameLayout(mContext);
mFrameLayout.setBackgroundColor(mContext.getResources().getColor(R.color.black));
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,
PixelFormat.TRANSLUCENT
);
WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(mFrameLayout, params);
Use service to create your system overlay view.
Not IntentService, just extend Service.
Make it work even if app goes to backgroung by returning "START_STICKY"
I want to create a gestureoverlay for an app. I want the gesutureoverlay to be ontop of all other views. I have done this with a textbox and a button so far. I have the below code which creates the overlay on top of all apps but I can not use anything else in any others app or home screen. The app takes away from being able to focus in on the background view. I do however get my gesture overlay to work.
How do I at the very least get the phone to work normally but get to see the swipes the user makes (create a gesture overlay) on top of all apps?
This is what I have so far
#Override
public void onCreate() {
super.onCreate();
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
GestureOverlayView g = new GestureOverlayView(getBaseContext());
g.setGestureVisible(true);
g.setEventsInterceptionEnabled(true);
wm.addView(g, params);
}
First of all, thanks because your code helped me to get my GestureOverlayView working on top.
I am working on something similar also and as far as I know you cant do this, at least just like that. To do that you need to have INJECT_PERSMISSION and this permission is grant only to system signed app, therefore you canĀ“t do it using Android APIs if you dont have your ROM sign.
Of course there are other ways to do that.
What you might do is to get events in your activity and "re-insert" them from your activity to the activity under you. And this is something you cant do through android.
Take a look here and here.
In these links you can find further information about how to inject event into Android system.