I want to create a button which will be shown on top of all apps.
something like this
as you can see, there is a button at top left corner. it can receive touch events and touch events can be received outside it by other apps.
I tried to use Theme.Translucent.NoTitleBar to my activity but it does not helped. I also set size to my button to [100, 100] but other activity behind it can not receive touch events. I think that the problem is in activity's window. it's size does not equel activity's size.
any help please
UPD
solved
hatcyl in Create a UI or a widget that sees on top of all Application in Android? says:
If you want something to be clickable, you can display it on top of
anything except the lockscreen.
You would to use a service and WindowManager to show a button on every App.
Related
I have a activity themed like a dialog and I have it setup so that it finishes when the user click outside.
this.setFinishOnTouchOutside(true);
As expected when the user clicks outside, it finishes. The activity is marked as floating activity and is only shown on top of the phone.
Now, if the user click on any other part of screen like the phone button/contact button on home screen, then the activity gets finished, but the user has to click on phone/contact app icon again to open phone/conatct app.
What I want is that if user click outside my activity, then the action must be performed as if the activity is not at all present on screen. Something like notification, which does not prevent user from doing other other tasks.
The only way you might be able to do this is by using a hidden WindowManager.LayoutParams flag, FLAG_SLIPPERY.
This allows touches starting on your View to continue to whatever View is below when the touch leaves your View but remains on the screen. However, I don't think this will work.
Android prevents you from touching "through" a touchable Window because it assumes that Window should be receiving the TouchEvent. Android also prevents you from programmatically "touching" the screen (without root or system access), most likely for security reasons.
I dug through AOSP for a while and found this.
Reading the comments, it's possible to infer that, while what you see doesn't take up the whole screen, the Activity's Window does. So, while nothing in your Activity is clicked, the Window is still overlaying everything, just with a transparent background, and is dealing with the touches that aren't passed to your Activity's UI. This brings us back to the "touching through" issue.
What Clean Master app does is that it put a widget on home screen and when user tap it , it cleans RAM and show an animation like this on homescreen(on top of homescreen) -
and i also want to do this ....
What i have done till now is that i have created a widget on homescreen and when user taps i received it inside an AppWidgetProvider class . shown here
I also think it shows this animation by using this feature - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT , like what messenger did by overlaying chatheads on top of screen. This can be done like this - here.
But i am still confused on what would be the best approach for doing this.
Any help would be appreciated ! Thanks in advance.
It is possible to create Activities with transparent backgrounds. These activities will appear over the homescreen but will still show the homescreen behind it. When the App Widget receives a broadcast, it can create a PendingIntent to start this transparent activity, which will then be displayed over the fullscreen.
There are some application that disables all the touch inputs, including the touch events that occur on the navigation bar.
Examples are Touch Lock or UnTouch. How one can do that?
By analyzing the second linked app seems that there is a hidden layout that capture the touch events (like an empty onClickListener).
Initially I tried to draw a transparent foreground using the SYSTEM_ALERT_WINDOW permission and by assigning an empty touch listener. However in this way I cannot draw on the navigation bar, so the user can touch the home button and the back button.
Another way that I tried is to launch an Activity with transparent background and in fullscreen mode. In this way I can capture all the events. This works, but obviously this causes other activities to go in pause state.
So my question is, how can one reach the goal? Alternatively is possible to use some root/system commands?
Thanks!
Try this link. If you want to do it on just 1 view then edit out the iteration in the methods given.
I need to know when the user is using the screen over my activity, even when he is not strictly on my activity (for instance when he drawed the notification drawer, or when he is on Messenger). That is because i want my app to do something after a certain time of absence of action by the user, and such cases mess with the timer, as the activity is not paused.
I tried with dispatchTouchEvent() and onTouchEvent() but they only handle event made on my activity.
So is there a way to detect touch event made on layout that has been drawn by other app over my activity?
You can cretae transparent overlay window by system alert. It always on top.
Then you can handle touch event and stretching further.
Creating a system overlay window (always on top)
I am developing an app which the Location of Caller on Incoming call Screen.
To show that I used Toast, But I came to about ann App which does this but not using Toast.
It uses something else to show something on Incoming Call Screen. I want to know what is that control.
The screen shot is attached here
As you can see in the image. I want to know about the control or View (that is in red Line Center).
This particular contriol can be dragged up and down and can be closed on clicking cross button
How to create this control.
you can use system overlays to put a view on top of all the screens..
check out following post for more info:
Creating a system overlay window (always on top)
Creating a system overlay where the home buttons still work?
AirCalc is one more proof of concept...