Question

I am currently working in a PhoneGap/Cordova app and I'm trying to use IndexedDB to store data. From what I read, Android support for it is rather scarce and so what works in my PC doesn't seem to work in my tablet (Android 4.0.4) nor my phone (4.2.1).

I have been trying to use the IndexedDB Polyfill as described in Parashuram's blog; however, it doesn't seem to work for my app. What's more, when I run Parashuram's example app in my devices, it doesn't seem to work and the unit tests fail.

Does anyone have any experience with IndexedDB and PhoneGap + Android? What have you used to make your app work?

Incidentally, IndexedDB seems to be implemented in both devices, since this works for both and I can create and open databases:

window.indexedDB = window.indexedDB || window.mozIndexedDB
    || window.webkitIndexedDB || window.msIndexedDB;

However, the onupdateneeded event does not seem to be fired, even though I'm using the jQuery IndexedDB plugin, which is supposed to work around different implementations.

Was it helpful?

Solution

I have experience with the shim in my project and it works for me on android. What version of Cordova do you use? It doesn't work on Android when using Cordova 3.2 or lower due to this bug: https://github.com/apache/cordova-android/commit/6e4ef508e8f9f2d396515bd1d7465481d2f1285c

Are you using the latest shim version? Because the older ones didn't successfully overwrite the native indexedDB object.

I'm also the co-maintainer of the project so if you have any questions feel free to ask.

OTHER TIPS

IndexedDB works great in PhoneGap on Android 4.4+ devices. I've used it, it's identical to using IndexedDB in Chrome.

Prior to 4.4, Android's WebView did not support IndexedDB. There are workarounds, like the shim you linked to, but that path tends to not be a lot of fun. If you can get away with targeting only 4.4+, that will make your life much happier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top