Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IndexedDB work in Android native app

We've got application to view some specific materials. Among material types there is HTML5 presentation that is shown in WebView widget inside app. And now we need to get detailed information about this view (for example slide show duration, list element pick where it is available, etc).

It is what customer wants - we can't change it.

We decided to use IndexedDB inside HTML5 to store information locally. Now storing works (as I know :) ). Next problem is to get this information by app and it is not solved yet. Unfortunately google didn't help me.

How to get information from IndexedDB file if I know its path? Or do you know another way to transfer data from html to native app?

P.S. Writing custom browser could not be solution.

Update

Found solution to load file from JS. In chrome browser it automatically saves in downloads. In android app I'm setting to WebView object DownloadListener to listen file save event.

Catching save file works perfect. But the url path is looks like blob:file/... and I can't get info from it. Tried using ContentResolver, create File object, replace blob: string with nothing, start ACTION_VIEW intent - nothing helped.

Update

Tried to use DownloadManager and DownloadManager.Request - it throws following exception

java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: file:///fa4857ad-0e86-454a-a341-123729e9ece0

Same with blob:file uri.

like image 327
Ircover Avatar asked Mar 21 '17 06:03

Ircover


People also ask

Where is IndexedDB stored android?

If there is an IndexedDb on Android it will be located on most devices somewhere below /data/data/com. android. chrome/ which is only accessible with root permissions.

What is IndexedDB and how is it used by PWA?

IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high performance searches of this data. While DOM Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data.

Is IndexedDB slow?

Not slow like a database on a cheap server, even slower! Inserting a few hundred documents can take up several seconds. Time which can be critical for a fast page load.

When should I use IndexedDB?

You might use IndexedDB to store structured data that's unrelated to any data on the server. An example might be a calendar, a to-do list, or saved games that are played locally. In this case, the application is really a local one, and your web site is just the vehicle for delivering it.


1 Answers

Is it a requirement to use IndexedDB for communication?

If not, you could add a javascript interface. Simply pass on the data as JSON string and then decode it on the java side.

https://developer.android.com/guide/webapps/webview.html#BindingJavaScript

Mind security (don't allow the user to browse to different pages, sanitize incoming data, ...) ;-)

like image 119
Michael2 Avatar answered Oct 13 '22 01:10

Michael2