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.
Related
Do you know an app for auto touching the screen for android, programming the time yourself? I know it's not a common question but I need it for a project. I searched a lot and come up with an app to "auto touch" the screen but copying your touches and I want it to touch for example if I set something like this:
In ms
touch(100);
touch(542);
touchFrom(1210,1382);
I know it's something pretencious but I want to know if there's something like that. If there's nothing then someone knows how to code something like that, something easy?
It is not possible for an ordinary app to fake input to another app, for security reasons, outside of perhaps on a rooted device.
Test suites using uiautomator can do this, but they are not apps. Accessibilty services may be able to do this, but they are not "something easy".
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
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 am writing an application for Android platform. The application is already almost written for 2.x version, but I want to make it also for Honeycomb version. As you know, Honeycomb has 'Fragments' rather than 'Activities' for tab target.
There is about 30 activities in my application and it must be changed to fragments. It could be very hard word for me, so I want to know the 'best practice' about doing it.
Thanks.
Not really an 100% answer, but just my personal experience so far (and please correct me, anybody, if I got something wrong - I'm still a beginner to Android):
I have the same situation atm and thought I could just re-use my activities and change the layout. E.g. I intended to show my main menu on the left side and all other activities on the right.
However, I soon realized that this isn't really working on Tablet. It just looked crappy and didn't even make sense as the Action bar pretty much replaced my main menu, if used properly. Also, the increased space really screams for a completely different layout. In my app, this will change the user experience completely, so I'll have to re-think the whole app.
On the other hand, stuff that I had to repeat again and again might now be replaced by "invisible" fragments with no UI. I haven't looked closer to this part of the Honeycomb API, but it sounds at least promising.
What I found a nice feature is that you now can "close" your app very easily. In my case I only have one Activity, so a simple "finish" gracefully quits the whole app. I know that this isn't the "Android way" to deal with app life cycle. However, while I don't miss the "close" button on my Android phone (even though some apps, especially games, offer one) I catch myself again and again looking for one on Honeycomb. (That's probably because the GUI reminds one of desktop applications.)
Anyway, long story short: I would recommend re-thinking you app for Tablet. You really have SPACE there, so it just looks strange if you don't use it properly. What this means for your app I don't know - it obviously depends on what kind of app it is. Some activities you'll probably can just use as fragments, some will merge with others, some might become dispensable.
So I guess you should decide first of all if your app really makes sense on Tablets. If not, you could just do the little "optimze" tricks (like applying the holografic theme and maybe new layouts/resources). For everything else I would wait for 4.0/Ice Cream Sandwich, as you will be able to use Fragments on both Smartphone and Tablet then.