WebView how to detect user selected the input box on the any webpage?


#1

Base on some reasons, I need to know the user clicks an input box on any webpage through WebView.

  1. Which kind of android listener I can use to detect use clicks an input box on the webpage.

  2. If the input box already has some texts, how I get them through WebView

  3. If I need to send some texts to the input box through WebView, how should I do?


#2

None, strictly speaking.

You would need to add JavaScript to your Web page that would catch the relevant DOM events, then have that JavaScript communicate back to the hosting activity. That communication could be via a callback registered via addJavascriptInterface() or through HTML message channels. I cover both in The Busy Coder’s Guide to Android Devevelopment.

Your JavaScript would handle that.

Use evaluateJavascript() or loadUrl() with a javascript: URL. I cover both of those in The Busy Coder’s Guide to Android Devevelopment as well.

The four Sensor* projects illustrate various techniques for communicating between an activity and JavaScript in a WebView.


#3

Thank you so much for your help, I already reach to addJavascriptInterface(), I am wondering how Android Browser apps detect all user clicks input box event. Or on the other hand, all these browsers did the same thing through addJavascriptInterface()?


#4

I do not know that they do detect it. I would imagine that it is handled in the Web engine that the browser uses.

I would imagine that major browsers use some other Web rendering engine. The Firefox family of browsers uses a version of Gecko that works on Android, for example. I would expect others to include their own builds of Chromium via the NDK.

Even for those that use WebView, there may not be a reason for them to find out about when the user focuses on an input box in their Java code.


#5

I through Android Presentation create back-end service and put WebView on external extend display because on the extend display WebView cannot get focus, so I can not open the soft-keyboard and make the input that is the reason I am seeking some solution, I want to make a kind of app which can support visit a website on extend display and doing other things on the phone. Input is a big problem in this case :frowning:


#6

Hi mmurphy:

Base on your WebView Sensor project, I have successfully set onfocus() attribute for all INPUT and TEXTAREA in the webpage, when user click input or textarea I can through an EditView get and set text and use soft-keyboard in cellphone screen. But I found, this solution not 100% cover all webpage, some time is not working, for example, Office 365 login page, I can set text in account name and password, but I will get warning “account name is not valid” when I click login, in effect all input is correct. Do you have any other good suggestions? I steel seeking a more powerful solution. Thank you so much.


#7

You could look at other Web rendering engines, such as GeckoView, to see if they give you more options.

Other than that, sorry, I am out of ideas.


#8

Thank you so much mmurphy, I will still tying.

One more question, how to get Presentation Dialog through WindowManager?


#9

If you mean "how do I get an instance of PresentationDialog from WindowManager", I don’t think that’s possible.


#10

:sweat_smile: All right thank you so much