Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Web Storage or IndexedDB from outside the browser in Android

I want to build an offline browser-based app using HTML and javascript to collect survey data on Android tablets. The app would consist of some static pages with forms for users to enter data, which would then be stored locally using Web Storage or IndexedDB. However, I also want to build a small native Android app which would grab this data and transfer it to other devices. Is this possible, and if so how would I go about it?

Specifically, I want to understand if and how the native app would access the browser's data store (I can manage the rest). I would prefer to use the Android browser but can use any other if that makes it easier. I have found this blog post which suggests that it might be possible but I would appreciate some pointers as to where the data is stored by the Android browser and how easily it can be accessed by another app.

like image 799
Stuart Avatar asked May 10 '14 22:05

Stuart


People also ask

How do I access IndexedDB data?

# View IndexedDB dataClick the Application tab to open the Application panel. Expand the IndexedDB menu to see which databases are available. notes - https://mdn.github.io represents a database, where notes is the name of the database and https://mdn.github.io is the origin that can access the database.

Does IndexedDB work on mobile devices?

Browser SupportThe latest versions of Firefox, Chrome, Opera, Safar, iOS Safari, and Android all fully support IndexedDB, and Internet Explorer and Blackberry feature partial support.

Is IndexedDB database supported by all browsers?

IndexedDB on Chrome is fully supported on 23-106, partially supported on 11-22, and not supported on 4-10 Chrome versions. IndexedDB on Safari is fully supported on 10-16, partially supported on 7.1-14.1, and not supported on 3.2-7 Safari versions.

Does IndexedDB work offline?

IndexedDB is an inbuilt non-relational database for browsers. It gives developers the ability to persistently store data in the browser, allowing for a seamless usage of web applications, even when offline. Two frequent terms you'll see when working with IndexedDB are database and object store.


2 Answers

Unfortunately I don't think the data flow can work the way you want it. In the Chromium WebKit implementation, IDB stores data in levelDB files that you should not be able to access (by design).

So how do we get Java and JavaScript to play nice together? That's a great question! As I see it, the only good way to transform Java data into IDB data is via the client-side.

I've got good IDB chops but my Android experience is non-production. From what I understand of it, here's a proposed solution:

  • collect data via native application views
  • write a string to a file in your sandbox with the data stored as a JSON blob or in an .html <script> attached to a JavaScript global
  • load a webview that can access a local URI like file://android_asset/blah.json and then run some IDB code to bulk insert it into IDB
  • use your IDB store to drive your web-based views

So the answer to "if and how the native app would access the browser's data store" would be: try the opposite. Architect it to let your browser access your native app data store.

like image 74
buley Avatar answered Sep 25 '22 00:09

buley


Easiest and most robust way to serialise all your records and load into your app when it first run.

like image 28
Kyaw Tun Avatar answered Sep 26 '22 00:09

Kyaw Tun