I would like to find a way for an Android app to interact with a web site, completely in the background without rendering the page in any view, without use of the main thread. The idea is for the app to run as a service, periodically authenticate, check a web page, and only alert the user when certain (rare) conditions arise.

For ease of getting it working, any library must act like a browser in the eyes of the destination web site (support cookies, and run JavaScript). And optimally, the library would allow the programmer to operate at a high level, such as "find button by name, click button", rather than the programmer dig around and find out that when the button is clicked, certain JavaScript runs before the form is submitted, and these umpteen form fields must be populated, for example.

The library should be interoperable with one of Android's features that allow sequential long-running processes, such as WorkManager requests (where a string of dependent operations can be enqueued to run one after the other, or, if something fails, to fail out). Alternatively, it could run as AsyncTask type or any other established background processing for Android.

The following are my impressions, which may be incorrect, so please advise if I'm off-base:

No Support for JavaScript

  • JSoup
  • HttpClient

No working Android version (also problem running headless?)

  • Selenium-HtmlUnit

Insists on a 'View' and main thread

  • Android WebView

I'm having trouble figuring out what happened to HtmlUnit. It appears that somehow Selenium co-opted it (but haven't done a lot of research on this). It would be great if this solution worked, but when I try to use it, I get an error, which links to this discussion. I'm wondering if Google didn't figure out a way to torpedo the open source community; they seem to have grabbed the source, integrated it into Android, then changed it so it no longer works.

There are apparently ways to hack the Android Looper to get WebView to kind of do what is needed, but it's less elegant (ie, harder to program), than HtmlUnit would be. And I'm not sure how well it would work as a true background service, with no foreground intent and no view.

If there are other libraries that might solve this problem, please advise. If one of the libraries above would solve the problem if I were more informed about how, also, please advise.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.