http://stackoverflow.com/questions/18213895/android-service-reads-localstorage
2
1
|
I have developed a PhoneGap application for Android. The application is composed by the webapp(HTML/jQuery) and a background service (Java code) that's started by the webapp.
This webapp writes to window.localStorage like
Is it possible to read this name that is in the localStorage from my Java code?
| ||
add comment |
2
|
This is possible. To execute JavaScript and get response you can do as follows:
Define JavaScript callback interface in your code:
Attach this callback to your WebView:
Run your JavaScript calling window.HTMLOUT.someCallback from the script:
Note -
window.localStorage['name'] is the same as window.localStorage.getItem('name')
You might need to use
super.webView.addJavascriptInterface or super.addJavascriptInterface to add the interface. You might need to use super.webView.loadUrl or super.loadUrl to invoke this. It all depends on where you are going to be calling these from. |
No comments:
Post a Comment