How to access the local storage of the Android browser through native code

I am developing an Android application that has to access the default local storage of the browser. Scenario:

  • Open the default browser for Android.
  • Download a page (which I designed) that saves some data in the browser’s local memory.
  • Close browser
  • Open my app
  • The application reads the data stored in the local storage of the browser and shows it to the user

Is there any way to access the local storage of the browser? Also, if possible, how to access the local storage of another installed browser on the device?

Thanks!

+4
source share
2 answers

It does not seem to exist. I tried to access browser data using content providers, but you can only access bookmarks and history.

I also did some tests using WebView instead of browser. I tried two approaches:

  • Access to the local warehouse database

You can access a local repository database, such as a regular SQLite database. Data is stored in one table with two columns - key and value. According to javascript documentation, writing to local storage is a synchronous operation. Excellent! The problem is that saving data from the browser (webview) to the file system is asynchronous. Therefore, if you write something in local storage, it is stored in memory, therefore it is accessible through the javascript API, but it is still not stored in the SQLite database.

  • Access local storage via javascript bridge

This is my personal recommendation! You created the javascript JavaScript interface and added it to the webview. This way you provide an API for javascript to access your code. Be extremely careful! This can be a serious security issue! Double check your code! After that, you can call your javascript methods as follows webview.loadUrl("javascript://...")

+3
source

I used the SharedPreferences Plugin to access my own repository instead of accessing the local repository of the browser in Phonegap. This may be useful for some. Github code

0
source

All Articles