Home > Net >  How to listen for javascript events from a native android application?
How to listen for javascript events from a native android application?

Time:01-07

I have a native Android app that has a webView that loads a web page I have no control over.

In app I need to track/detect a “MessageEvent” that happens when a button is clicked on this page within the webView.

Scenario: User presses a button within the webView which fires off a "MessageEvent", When this “MessageEvent” is detected, a method in the Java/Kotlin code needs to be called, either through a listener that waits for this “MessageEvent” or another way(irrelevant how the method is called).

My main concern is how to detect this javascript “MessageEvent” event within my Java/Kotlin code.

CodePudding user response:

The answer here depends on why you want it ! One way to do it is with updating a field in database when the event is triggered and you need to have a looping check in your java code that asks the same database if the event was triggered ...
Also, You can't access that information directly ! Witch is very good to provide security for the user … imagine you take the user to his PayPal account and he sees a perfectly functioning PayPal web page with all purchases. If your android app has access to the scripts in his website, i think we all know what can happend.

CodePudding user response:

I found the solution that seems to have worked, it was posted on another Answer:

https://stackoverflow.com/a/62500309/7849477

Hope it helps someone else.

  • Related