Sorry for the poorly worded title, allow me to explain.
I have an idea for a translator app that will translate any text across all apps. Is it possible to create a listener that can watch all apps, and whenever a TextView is created, modify the content if the content contains a certain keyword?
Thanks!
It may be possible through the Accessibility API, by implementing an AccessibilityService. I've never used it myself, so I'm not sure, though.
But AccessibilityNodeInfo sounds promising:
This class represents a node of the window content as well as actions that can be requested from its source.
Related
There are several articles/tutorials to use Accessibility service on Android to find elements by id/text but there is None (that I could find) which makes use if XPath.
As far as my understanding goes, Accessibility service would take a snapshot of the current ui hierarchy with corresponding attribute and then would search the id/text.
This is significantly slower than having a direct XPath to the element we already have knowledge of - no need to take snapshot of whole ui or search for text in it. (Please correct me if I'm wrong) and can even interact when the item is below the screen; i.e. it has potential to click item when it's not visible yet and will be so after scrolling.
Android does have support of javax.XPath https://android-doc.github.io/reference/javax/xml/xpath/package-summary.html but I couldn't find any sample to try it on.
Any link/resource/guidance will be appreciated. Use of external libraries is fine as well assuming it doesn't hinder performance. Idea is to click an element (I have XPath for it) as soon as it is inflated/rendered in apps making use of some kind of webview element.
Think you ideally needed to mark up or censor a list of keywords in visual output systemwide, yet cant require to root devices.
That still works on websites through browser plugins.
But is it any thinkable to mess with popular apps like whatsapp, facebook, (one at a time) ?
Reading: I know it is possible to read/change some text inputs yet not generally/all? http://developer.android.com/training/accessibility/service.html
A universal way for markup could be determining screen coordinate positions of contents by OCR and set transparent overlays on the fly + algined smooth with scrolling, just not convinced how well this can both work and be battery efficient (we could cope with low accuracy in text recognition)
I'm adding all my reputation as a bounty.
Laying out a good way for any one popular app (top 20 social apps) qualifies as an accepted answer!
Laying out solution for "1." only but for two or more apps also qualifies.
Showing specifically why/where it will work with one app but not with another also qualifies as an accepted answer.
You cannot modify the visual output of an app. The closest thing you can do to accomplish this is like what Facebook Messenger and LastPass use, which is a feature that allows them to draw over the top of other apps, and LastPass specifically can also read the contents of another app via accessibility permissions. However, that just allows them to draw over the existing apps, and in the case of LastPass, fill out text into input fields. Even with the above options, I don't think you'll be able to accomplish what you're looking to do.
I don't think it's possible. Each app on the Android runs in its own sandboxed environment. You can only communicate through Intents with other applications. So unless they're listening for bad Intents(which I hope they're not), you can't really do anything to those applications.
I have android application that is written "regular" way. layouts, java, APK.
Now, depending on some factors I want data to be presented differently to different users with different preferences, etc. Doing it using XML layouts will be very problematic in couple of reasons:
Upgrade issue - we have bunch of users and they not good at upgrading.
Hard to maintain and code.
So, I'm toying with idea of "templates" where we can serve templates from server and just use device to generate those.
Web app won't work because our data available offline in case there is no connection.
There is buttons and stuff that user can press to call regular Activities and do things.
I envision something like:
HTML 5 template with {tags} that I will populate from data. I will receive tempaltes and data separately from server. I will merge that data and display on UI.
Now my question is how do I:
Display HTML5 inside Activity
Intercept button push in HTML in my Java code?
Is this bad idea to write something like this?
It sounds reasonable to me. You can use a WebView for displaying the content. Your app can manage a cache of downloaded templates and other content and display it in the web view either from the web site or from the cache if offline.
I think your objections to layouts are offbase. You really might be better off with layouts. Here's why:
Your app can be set to auto-update by users if you do not change permissions. But pushing updates to your app will remain an issue unless your app is entirely web-based. (not a bad approach by the way) But so long as you have a native app, you will need to push updates from time to time.
And as far as being hard to maintain and code, layouts are specifically designed to make this type of customization manageable. You can break pieces of the layout common to different settings into separate files, and add them with includes.
You can use fragments to adapt to a variety of form factors.
You can serve up different layout based on screen size, language, orientation, or any of a wide variety of variables.
Check out some of the series on layout tricks, and get more familiar with being a layout power user. I think in the long run it will save you a lot of effort, assuming you don't switch to making your app a web app instead.
http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
http://developer.android.com/resources/articles/layout-tricks-merge.html
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
http://www.curious-creature.org/2009/03/16/android-layout-tricks-4-optimize-part-2/
Google: Android Layout Tricks.
Great stuff.
Another benefit: Compiler checking. No broken functionality because a variable or field has the wrong name. Not the case with HTML.
Another benefit: works offline too with no messing around.
And last - you will have a non-trivial amount of work attempting to get this hybrid HTML stuff working the way you want, and then have a very unusual and custom code base that nobody here on Stack Overflow will be able to help you with. Stick with Layouts and there are lots of experts who can help you tackle the stickiest layout puzzles.
I have a long "cities" list. I was looking for an equivalent to
sectionIndexTitlesForTableView in the iphone world. It provides a way to "jump" to a particular point in long lists without having to scroll through all the elements. I think FastScrollView implements this but it's not part of the API and I can't find any documentation on how to use it. It appears in the baked in contacts application of the device. I want to use this functionality within an AlertDialog. Is this possible?
Fast scroll can be used for any list; the most common being the alphabetical lists. You can write your own custom SectionIndexer for other fast scrolling operations such as moving to a list based on some other attribute of your list item (e.g. name, address - where section indexer will be alphabetical, and phone number, address etc where it can be numerical)
P.S. This is more of a comment aimed at matto1990's answer.
Fast scroll is something you can only use in alphabetical lists really. The view which pops up (to show where you are) can only provide space for a single letter. I've looked in the source code for ways to extend it, however lots of the methods needed are protected and can only be used by classes in the same package (the core framework one).
The only thing I can think to do is to just write it all yourself. It's annoying but until Google make it possible for us to extend it via an API that's the best that's possible.
My similar question
I would like to create a search in my app which acts like the map search in the Google Maps app.
I have creates an an auto complete text view which updates dynamically based on the results of the Geocoder.GetLocationByName() Method.
However the results retrieved from this function are really bad and not at all consistent with the text I pass to it.
Is there a better method of doing this to achieve accurate results?
So it's not the geosearch that's your problem, but the autocompletion, right? Well I assume you need the whole set of possible values in order to obtain a decent auto-completion. Another way would be to take apart the google javascript code that performs the auto-completion and talk to their servers, pretending you're typing into one of "their" fields. However, this isn't only probably against their terms of service but also a bit shaky because they might a) detect and prevent this or b) change their interface in the future.
Your best guess would be to get a list of all cities, streets, etc in question.
hopefully this should be able to do the trick :=)
https://developers.google.com/places/documentation/autocomplete
good luck (testing it myself right now)