Increase the size of the WebSQL quota in a WebView

前端 未结 2 1252
野的像风
野的像风 2021-01-18 21:12

In a normal Android web app the maximum size for a WebSQL database is normally around 8MB. In a hybrid web app I am making I would like to increase this limit. How would I g

相关标签:
2条回答
  • 2021-01-18 21:46

    You may want to look at this other question on how to increase quota limit.

    Looks like changing the size is only a problem for users that already have a local DB created, this is because there is no way to change the size of the DB when running upgrade scripts for versioning. That said, you just only need to change the size in the initialization script (code in JavaScript):

    var size = 10 * 1024 * 1024; // changed from 5 to 10MB
    var db = openDatabase("oversized_db", "v1.1", "Ten MB DB", size);
    

    Take into account that this will only affect new users. All users that have previously created a DB with a different size need to clear their cache (you have controll of the cache on a webView so its not that bad) but all previous data would be lost (unless you manually migrate it to the new DB with native code). In my case I have to do the same but decreasing the size. That would take care of the issue.

    Hope this helps.

    0 讨论(0)
  • 2021-01-18 22:01

    The quota for a web app seems to differ from that of a hybrid app (as in something running within a view). Regardless, by implementing the following in your android.app.Activity subclass you will double the quota until it finally stops at approximately 48MB.

    @Override
    public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
        quotaUpdater.updateQuota(estimatedSize * 2);
    }
    

    The user will not be asked to interact when this happens.

    0 讨论(0)
提交回复
热议问题