I would like to display a message to the user for some asynchronous event. For example for an alarm expiration. I would like to display a popup or dialog that is displayed over any activity is the foreground at the moment (and this can be some other application activity) leaving the current activity in the backgound.
Is there a way to do so in Android?
First off, you will be told that this is a bad thing to do, that it is against the Android way of doing things. Users do not like this. And that the Notification area is much better way to do this.
That said... there are ways to accomplish this...
A Toast will display no matter which activity is on the screen. So you could set up a background thread (or better a Service) that will display your information in a Toast. This might be good enough for you.
You may find it useful looking at some Toast source code here.
Also here is a nice page on how to create a custom Toast layout by replacing the default View with one of your own. (I have not done this, but it looks quite interesting):
Custom Toast Alert on androidexample.com
The alternative is much more difficult, and is to display a System Overlay window. Unfortunately you have to do quite a lot of work to get these set up properly.
Here are a few related questions that I used to get it working:
Creating a system overlay window (always on top)
System overlay android 4.0
How to create a system overlay in Android which allows interaction with the windows below it?
Each of these has links to many others - there are loads of System Overlay questions on here.
But things to remember:
In the old days, you could put a system overlay on top, and send
touches through to the activity below. This is no longer possible,
and so a lot of the answers are now out of date.
You may need to
play around with the flags in the provided examples to get exactly
the effect you are aiming for. Not all the examples use the same
flags, so there are some subtle differences in how each solution
works.
Then again, I also believe that the Notification area is a much better UI pattern to use, so I do recommend you try that first. It is easier to do, and most of us expect that type of behaviour rather than a pop-up.
The problem with a pop-up, is that it might interrupt a movie I'm watching. Or a game I'm playing.
Yes, i had created two dialog for income event for background and foreground
Related
What i wanted to do, and didn't find any suitable solution, is :
create a scene in tasker (no problem on doing it :) )
display this scene on overlayed mode on other app (ex: waze,). Overlay is mandatory (as i know but i am maybe wrong) to let's the underlayed application work and refresh screen normally
allow interaction with button on the scene, just like we can do it if i choose the dialog mode for my scene. The problem with dialog mode is that the underlayed apps screen does not refresh.
In fact what i wanted to to is to display some button when i am running waze, to allow me to sens ETA Sms to my wife, or skip to the next track on my musics apps, or close waze quickly.....
As a resume i want to do what is
create floating windows like offered by apps like Overlays
but only using tasker
Best regards
Best
Please share some images of your requirements so that we can help you better but anyways I found a solution maybe it'll help you with some little customization.
According to my understanding, you need something like this:
You can download the whole project and customize it according to your requirements from Here
I'm developing an app that intercepts toast messages and displays them in a custom view.
The interception part is easily implemented using the AccessibilityService.
The tricky part is how to suppress the toast messages from appearing (or at least make them invisible). I know (to the best of my understanding) that this is not possible in normal circumstances.
But does anyone know any hacks that would allow me to suppress the toasts from appearing or make them invisible?
Would it be possible with root permission?
Note: I'm relatively new to programming. Nonetheless, I had a look at the android source code for Toast.java (link). Would it be possible to intercept the show() method or any other relevant method to stop them from appearing (maybe with root permission)?
According to Dianne Hackborn here, you can't. Yes, I realize that post is over four years old, but I haven't seen anything in the SDK since to overcome that.
Yes, you can use an accessibility service to detect toasts, but that's only so you can do something in addition, like TTS, not to stop them.
It would be a bad day if you could. For example, junk apps that pastes shortcuts on your desktop. Root apps that require SuperUser. In both cases, a toast pops up to let you know that something out of the ordinary is happening. That's a good thing, and if I ever found an app that was suppressing toasts, it would be gone instantly.
Moral issues aside, you could do this if you changed the OS source and compiled it on your own, but it would still only work for users that had that particular ROM installed.
As another option, have you tried creating your own Toast instead? You can give it a custom View, and if it's timed right, it will show up just after the normal one. Then it would overlap and you won't see the first. I'm not sure how feasible it is, but it's a thought.
I went through some posts, but most of them discuss placing a image or a string with information on it.
I however need to place button that manipulates some call features.
Is there a method to do that universally works throughout all android distributions?
(I thought to pop up custom screen with my button above usual screen. Is that good idea, or is there more straightforward way to achieve this?)
Thanks a lot
On stock devices there isn't going to be a legit way to put your own button "on" any portion of the Dialer application Activities (including incoming call screen). This kind of functionality would require the Dialer to explicitly provide an API for it. The stock system prevents applications in the background from placing their own clickable regions "on top of" whatever is currently in the foreground . (It's a good thing too, the bad reasons to do this far outweigh the legit ones.)
If you are wanting to do this you're going to have to look into building your own version of the OS that allows for it. OR potentially if you unlock your device enough to be able to install your own application that handles all of the functionality of the Dialer. Then you could provide an API for a third party application to do it(or just "bake in" your button to the Dialer) But I imagine that being able to get it all hooked up correctly to actually make your calls would be mighty difficult.
I am looking for some help, not being spoon feed source code (which from some of the threads I have read on this forum wouldn't happen anyway). I am really just wanting to know if what I have conjured up in my head is even possible or not, and if it is if I could get pointed in the right direction. So, I am looking to add a "view", doesn't really matter what type the concept would be the same for all of them, to appear when receiving or placing a phone call. You know the one that has the little droid waving at you or a photo, etc. The only thing is that I would only want like the top 30px to be this "view".
For instance, you receive a phone call and at the top of your screen on top of the receiving call window is a TextView with a note about this person (i.e. - he stinks).
The only thing I have been able to come up with so far is that I would have to bring up a layout that was either invisible or gone, but have yet to figure it out as of yet.
Am I barking up the right tree or do I need to find a different tree to sniff. Any and all help would be appreciated.
I honestly don't know the answer to this, but if it were possible then presumably you would have to have your own custom Activity launch in response to an incoming phone call event. This Activity of your own would replace the standard system phone application. So I did a search on here and the most vaguely related previous questions I could find within a short time are these:
Is it possible to write a new "phone" activity, and if yes then how?
Launch an activity at end of a phone call on Android
Answers on those seem to suggest the phone would need to be rooted before you could replace the standard phone app for receiving calls.
I'm making a popup in Android using Toast, is there any way when shown to blur the window behind. I'd usually use:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
But in this case am not sure how to go about it... Any help would be great, thanks!
A Toast is designed to be unobtrusive and only appears for a short time so blurring the background would stop the user from continuing to use the phone. From the Android SDK:
When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.
You would be better using a Dialog if you want to guarantee the user's attention, you should then be able to blur the background:
http://developer.android.com/guide/topics/ui/dialogs.html