IndexedDB works in Android app

We have an app to view some specific content. Among the content types, there is a view HTML5

, which is shown in a widget WebView

inside the application. And now we need to get detailed information about this view (for example, the duration of the slide show, select the list item where it is available, etc.).

This is what the client wants - we cannot change it.

We decided to use it IndexedDB

internally HTML5

for local storage of information. Works are now stored (as I know :)

). The next problem is getting this information on the application, and it hasn't been solved yet. Unfortunately Google didn't help me.

How can I get information from a file IndexedDB

if I know its path? Or do you know another way to transfer data from html to your own application?

PS Writing a custom browser might not be a solution.

Update

Found a solution to download file from JS. In Chrome browser, it automatically saves downloads. In an android application, I am setting an WebView

object DownloadListener

to listen for a file save event.

Capturing the save file is fine. But the url looks like blob:file/...

and I cannot get information from it. Tried using ContentResolver

, creating an object File

, replacing the string with blob:

nothing, running the ACTION_VIEW

intent - nothing helped.

Update

Tried to use DownloadManager

and DownloadManager.Request

- it throws the following exception

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

      

It's the same with blob:file

uri.

+3


source to share


3 answers


We decided to use ServerSocket

localhost as a web server on the device. And then it Html

sends an http responce to it. Maybe using java script bindings as @ Michael2 wrote would be better, but our solution was implemented prior to posting it. :-)



0


source


Is IndexedDB required for communication?

If not, you can add javascript interface. Just pass the data as a JSON string and then decode it from the java side.



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

Protection from the mind (do not allow the user to view different pages, sanitize the incoming data, ...); -)

+1


source


You can solve the problem by hacking by calling a JavaScript function from Java and returning the required attributes in a specific template. To realize this

  • Create a javascript function that will return attributes in a specific template.
  • Create a WebChromClient and override the onJsAlert () method. message The onJsAlert parameter has a returned message string. Disassemble to get the required attributes.
  • Call JavaScript function from Java code to get value.

    final class MyWebChromeClient extends WebChromeClient {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            result.confirm();
            // Parse the message to get the required attributes
            Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
            return true;
       }
    }
    
          

To call a JavaScript function to get data, use the below code. Here testFunction () is a fucntion that will return data in string format.

webView.loadUrl("javascript:alert(testFunction())");

      

Instantiate WebChromeClient and set in webview and also don't forget to enable JavaScript.

WebView webView = (WebView)findViewById(R.id.web_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new MyWebChromeClient());

      

+1


source







All Articles