0

Probably a simple question, I can call a native function from the JavaScript, for example:

Android.setVolume(0.7)

However, I do not know how to trigger (from Android/Java), or handle events (JS) that are not caused by user interaction, for example, alerting the JS when the user's network state changes, the battery gets below a certain point etc.

Any help greatly appreciated.

1
  • Actually, just found this answer here, stackoverflow.com/questions/7544671/…. The answer is over a year old and is labelled as a hack, is this still the best way to do it? Commented Apr 25, 2013 at 14:18

1 Answer 1

1

However, I do not know how to trigger (from Android/Java), or handle events (JS) that are not caused by user interaction, for example, alerting the JS when the user's network state changes, the battery gets below a certain point etc.

As with the answer you linked to, use loadUrl() with a javascript: URL, akin to how a bookmarklet works.

The answer is over a year old and is labelled as a hack, is this still the best way to do it?

I am not completely clear why the author of that answer described it as a hack. Certainly, it's viable and is used a fair bit.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.