How can I call Android JavaScript functions in WebView?

Is there a way to pass a message from an Android browser to an app?

  • I have a situation where I'd like for some data to be passed from a mobile web site to a native Android app. A complication is that, in the normal case, the native Android app might not be installed when the mobile web site is loaded. Here's an example: I am a user of ExampleApp and I want to share a particular piece of data from ExampleApp with you, who has never installed ExampleApp. I send you an email with a link to a mobile web page that knows what piece of data you want to see when you open the link. But, since the data is only available in the native app, not the mobile web, you're taken to a page that asks you to go to Android Market and install ExampleApp. You install ExampleApp, and ideally, you'd be taken directly to the piece of data that I shared with you. The big problem is in the disconnect between viewing the mobile web page and the installation of ExampleApp. I've thought about a couple solutions, but neither have been successful (that said, I could just be implementing them incorrectly): Set a cookie on our domain that includes the data when the mobile web page is loaded. Then, when ExampleApp is opened, start a WebView to request a page on the same domain and check the value of the cookie. Use that to determine what piece of data to show in ExampleApp. Use JavaScript localStorage to store a reference to the piece of data and use a WebView to get a page on that domain and request the content of localStorage from within ExampleApp. In both these situations, it seems as though the WebView and the Browser are sandbox'd away from each other, so you can't get at the cookies/localStorage between the two. Is there any other way to "leave a crumbtrail" or set a message that an app installed later can access from the Browser?

  • Answer:

    yes you can - you use data intent filters to catch certain protocols or URLs.have a look at http://developer.android.com/guide/topics/intents/intents-filters.html and scroll down to "data test"

Warren Miller at Quora Visit the source

Was this solution helpful to you?

Other answers

I don't think that is possible. I would make the data accessible on the webpage since it's a great alternative for people who don't have an android phone (or another mobile OS). Or you could add some kind of authentication to your application so the user must login with his email address and a chosen password before he can continue to use the application. This way you can link the email address to the data you want the user to see. So basically this is what would happen: User sends other unknown user an email saying that he has information available. User reads mail, goes to the website and needs to create an account before continuing. User installs app from the market. User logs in to the app using his email address for which he made an account in the second step.

Youri D.B.

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.