Open mohopa opened 10 years ago
Hey ! Have you just tried to make this project compile as is ? Or have you changed smthg ?
hey both, first try to use it without any change but javainterface function does not call then change in project something ,also happen nothing. I solve my problem (multiple webview whit one localstorage) by add webview's id to webview localstorage "key-value" , of course if can use java database will be better. thank you for any help :)
Well... Normally, without any change in code, the given sample should work... You said javainterface function does not call... What exactly do you mean ? which function are not called ? Has the project been built correctly ? What logs do you have in logcat when you launch the given sample ?
I was surprised too,it work for other, maybe I do mistake !? I put breakpoint on each method in javainterface class and then debug the project but none of them call. in script tag I tried to change "localStorage.getItem" (or other localstorage using) to "LocalStorage.getItem" (with upper case 'L') then "getItem" method called. I know this is not true to change "l" to "L" but it work just when do this. about logcat it shows some message like this : [INFO:CONSOLE(79)] "value myValue set for key myKey", source: file:///android_asset/index.html (79)
Hi,
at the beginning of the HTML page in the projet there is theses lines :
try{
//we replace default localStorage with our Android Database one
window.localStorage=LocalStorage;
}catch(e){
//LocalStorage class was not found. be sure to add it to the webview
alert("LocalStorage ERROR : can't find android class LocalStorage. switching to raw localStorage")
}
this should replace the classic web localStorage by the java one. Do you have this code in your pages ?
Try to replace alert("LocalStorage ERROR : can't find android class LocalStorage. switching to raw localStorage")
by $("body").append("LocalStorage ERROR : can't find android class LocalStorage. switching to raw localStorage")
and see if you have see the error in the page
yes these line exist in mine, I did not change any code,just download it and compile.
I changed "alert" to that you said but nothing appended to 'body' so java database should be created ,therefore try to run it In android default emulator(before, run on real device and genymotion device) then try to explore in files and try to find "local_storage.db" but surprisingly, nothing was created in "data/data/packagename" of course there was another folder with name "localstorage" and in that folder a file with this name "file__0.localstorage" also some other db ("Database.db","webview.db","webview.db-journal","webviewcookieschromium.db","webviewcookieschromiumPrivate.db").I'm confused !!!
any way ,thanks for all the help
For some reason I got the same problem (Android 4.4.4); Everything works OK but the window.localStorage
object is not overwritten with our custom LocalStorage
object.
Finally decided to do it the other way around: check if custom LocalStorage
is available and assign to custom top level object _storage like this:
_storage = window.localStorage;
if (typeof(LocalStorage) !== "undefined") {
try {
_storage = LocalStorage;
console.log("Using custom LocalStorage class");
}
catch (e) {
console.log("ERROR with custom LocalStorage class");
console.log(e);
}
Now use _storage
in place of any localStorage
@squio you saved my time. I believe some methods used here is deprecated in KITKAT. So it's not create java database. After applying your changes it's working perfect with Java database.
@didimoo Thank you very much for your code and it's very grateful if you apply the kitkat patch.
No time at the moment @mohanmoorthy to apply updates for KitKat... But if you have a solution, feel free to fork the project :)
Sure Diane. Let me do it soon.
On Thu, Sep 4, 2014 at 1:35 PM, Diane notifications@github.com wrote:
No time at the moment @mohanmoorthy https://github.com/mohanmoorthy to apply updates for KitKat... But if you have a solution, feel free to fork the project :)
— Reply to this email directly or view it on GitHub https://github.com/didimoo/AndroidLocalStorage/issues/4#issuecomment-54426995 .
With Regards
Hi all!
I wrote the original try/catch statement ;) I don't really understand why kitkat doesn't want to override window.localStorage
with the native interface.
I will make a few tests soon. thanks for the feedback
There has been no comment in this issue for over a year. I assume there is no workaround for this?
it seems that this project does not work,it still use webview localstorage. I try to debug it but java interface function does not call !!! when change "l" to "L" they have been called, but javascript could not recognize function answer