Check if webpage / webview contains certain words (android)

I am creating an application and I would like to give a notification to the user if the web page (which displays the canceled classes) contains the class you are in.

How can I do that?
Should I use webview

and reload every x minutes in the background and check if it contains certain words and if so, please report it? And if so, how can I check certain words in webview

?

0


source to share


3 answers


This is easily accomplished in a WebView, without unnecessary code. The following code will find the string (you can also set the FindListener to tell you if / when a string is found, I haven't used it, but it's there):

String string = "text you want to find";
webview.findAll(string); //works for API levels 3 - 16
webview.findAllAsync(string); //works for API levels 16 and up

      



As you can see, you will have to use both methods if you want to support API levels below 16. Both have the same listener, although you only need one listener, check the link above.

+2


source


I haven't done this in Android. But I did it in other environments. You can fetch the last page from the cache and parse it. Else, use Java to unwind each page and parse. Mr. van Raak has a good understanding of the service. Perhaps you already have it and can add it. While JSoup is handy, it's pretty chubby. You can easily make your own lightweight filter.



+1


source


If the data is not available by any other means (like an RSS feed or some other url request), you can clear the webpage with something like jSoup . You can just give jSoup the URL of the webpage and it will return the raw HTML of the webpage. You can travel through DOM elements and get the exact text you want.

You will also need to create an Android service that will work even if you are not using the app. Every X minutes, this will clear the web page and give a notification if necessary.

0


source







All Articles