I'm developing a mobile app using phonegap & jQuery mobile.
I'm having reports from QA that on the Samsung Galaxy Y (android 2.3.6) - localStorage is null and therefore causing the app to crash.
As far as I can tell, localStorage should be supported from android versions 2.0+, and I have even added the following code to the DroidGap class:
super.appView.getSettings().setAllowFileAccess(true);
super.appView.getSettings().setDatabaseEnabled(true);
super.appView.getSettings().setDatabasePath("/data/data/" + appView.getContext().getPackageName() + "/databases/");
super.appView.getSettings().setDomStorageEnabled(true);
So I'm struggling to understand why localStorage doesn't seem to be supported on this particular device. I'm told that it even runs OK on other devices with the same version of Android!
Are there any settings or other things I'm not aware of that could cause localStorage to be null??
You can run logcat from the android SDK installation folder's platform tools folder, on my machine this is: C:\Program Files (x86)\Android\android-sdk\platform-tools
Just run adb logcat
from the command prompt. You will get lots of messages.
I have created a test app and ran it on a Galaxy Y that has the following code in the onDeviceReady function. Using logcat it shows the not supported message
if (typeof window.localStorage == 'object')
{
// localStorage is supported
console.log('**HelloGap: localStorage is supported');
}
else
{
// localStorage is not supported
console.log('**HelloGap: localStorage is NOT supported');
}
You can filter the messages from logcat but I haven't been able to get that to work so I just redirected the output to a text file and searched it for **HelloGap
So it turns out by upgrading Phonegap (cordova) from 1.8.1 to 2.0.0 fixes the issue....
I had problem with 2.3.6 and localStorage also so I tested 2.3.3 and 2.2 AVD images together with Cordova 2.2.0 and it seems that localStorage is supported but should be called as window.localStorage and not without window scope but what is working on Android 4.x and in Desktop Chrome. But there is another problem that localStorage is not persistent when application is restarted, and I see equal problem in Hydratation, which offers again and again app reinstalation, so I think that is affected by same bug.