Maxime Rouiller
Maxime Rouiller

Reputation: 13699

Intents in a browser, is it possible to trigger an intent from Javascript in the Android web browser?

Quick question that I can't seem to find an answer for.

If I am in the Android web browser... is it possible to fire a "Share" intent with JavaScript? Just trying to streamline the "Share to..." process.

It might not be possible but I would just like to confirm it before I announce that to my team.

Added info:

I do not have any Android application running. Only an HTML file and a JS file.

Upvotes: 3

Views: 2540

Answers (2)

nicholas.hauschild
nicholas.hauschild

Reputation: 42849

It most certainly is possible. Take a look at the WebView.addJavascriptInterface() method, as it should be able to provide you exactly what you need.

The basics of using addJavascriptInterface() are detailed here.

  1. Create the class that will fire the intent. This is typically just a standalone class (no need to extend a Service or Activity).
  2. Bind this class to your WebView (This would be the addJavascriptInterface() call).
  3. Call the corresponding method from your Javascript.

Upvotes: 1

ChristopheCVB
ChristopheCVB

Reputation: 7315

If you redirect the user to a link that your application Activity intent filters are cibling, yes, it is possible.

Upvotes: 0

Related Questions