New Plugin: Browser Storage, Session, Local & Cookie Storage - Offline Storage

Hi @jamesonvparker, Short answer is yes. You do not need to include any extra permissions (except the obvious <uses-permission android:name="android.permission.INTERNET" />) in your manifest file and the good thing (for us) is even if the user clears your apps cache the local storage will live because its actually stored in the webview cache. I want to mention thought that there is actually a backup/local storage on device feature set on the android OS that can web leveraged through webview if your writing your own wrapper but in your case specifically you could have your data push/sync to the default contacts as the backup but also as a feature point. I have seen a lot of posts based around android wrappers on the forum and ive been meaning to put my 2cents worth down as far as a few tips that can help out, here are a couple of java methods worth knowing should you be building your own wrapper.

  • .setJavaScriptEnabled(true);
  • .setAppCacheEnabled(true);
  • .setAllowFileAccessFromFileURLs(true);
  • .setAllowFileAccess(true);
  • .setAppCacheEnabled(true);
  • .setBuiltInZoomControls(false);
  • .setSupportZoom(false);
  • .canGoBackOrForward(0); - mainly for single page apps, it will stop even the return arrow key from leaving the app.

One thing that should be done is telling your webview container that it is only to use your domain or it will return to your domain,

yourWebViewsID = (WebView) findViewById(R.id.webview);
yourWebViewsID.setWebViewClient(new WebViewClient() {
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if(url.contains("yourapp.bubbleapps.io")) {
      view.loadUrl(url);
    }
    return true;
  }
});

and also, if the user has the internet disabled, flight mode, no reception, bubble goes down and so on, its wise to include a method of returning the users view to a local stored html file (especially in your use case as its what will happen when the user is offline),

yourWebViewsID.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        yourWebViewsID.loadUrl("file:///android_asset/yourOwnHTMLFile.html");
    }
});

there really are no limits here when you go down the I’m doing it myself road, but my highest recommendation is to include firebase, see HERE.

1 Like