I've got a simple Android app that has a WebView. The WebView is set to browse to a site which uses JavaScript's localStorage feature.
I've already got my WebSettings set to allow DomStorage:
webSettings.setJavaScriptEnabled(true);
ebSettings.setDomStorageEnabled(true);
String dbPath = this.getApplicationContext().getDir("database", MODE_PRIVATE).getPath();
webSettings.setDatabasePath(dbPath);
What I need is a way that my Java code can read a variable stored using the localStorage mechanism, ie.:
The JavaScript does this:
var storage = window.localStorage;
storage.setItem("name", "Hello World!");
How can I read the value of "name" from localStorage from Java code?
yes possible to read localStorage value in java (Android).
use this plugin https://www.npmjs.com/package/cordova-plugin-nativestorage that use native storage .
-for that we have to set value in cordova
NativeStorage.setItem("reference", obj, setSuccess, setError);
function setSuccess(obj){
}
function setError(obj){
}
And In Anroid Java File to get this value :
SharedPreferences sharedPreferences = getSharedPreferences("MainActivity", MODE_PRIVATE);
System.out.println("********--------- shared pref values... " + sharedPreferences.getString("myid", "no value"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With