Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase the size of the WebSQL quota in a WebView

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 go about doing that?

It seems that WebStorage might have something to do with it, but the only method I can see there that seems to set the size, setQuotaForOrigin, is marked deprecated.

Sample code (that is not deprecated) is welcome :)

like image 829
oligofren Avatar asked Aug 14 '13 16:08

oligofren


2 Answers

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.

like image 175
oligofren Avatar answered Oct 22 '22 07:10

oligofren


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.

like image 1
Chepech Avatar answered Oct 22 '22 09:10

Chepech