Created
June 19, 2012 12:28
-
-
Save xoan/2953856 to your computer and use it in GitHub Desktop.
HTML5 WebDatabase support in android WebView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.webview; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.webkit.WebChromeClient; | |
import android.webkit.WebSettings; | |
import android.webkit.WebStorage.QuotaUpdater; | |
import android.webkit.WebView; | |
public class WebViewActivity extends Activity { | |
private WebView myWebView; | |
private WebSettings myWebSettings; | |
private String databasePath; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
myWebView = (WebView) findViewById(R.id.web_view); | |
myWebSettings = myWebView.getSettings(); | |
databasePath = getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); | |
myWebSettings.setJavaScriptEnabled(true); | |
myWebSettings.setDatabaseEnabled(true); | |
myWebSettings.setDatabasePath(databasePath); | |
myWebView.setWebChromeClient(new WebChromeClient() { | |
@Override | |
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, | |
long totalUsedQuota, QuotaUpdater quotaUpdater) { | |
quotaUpdater.updateQuota(estimatedSize * 2); | |
} | |
}); | |
myWebView.loadUrl("file:///android_asset/index.html"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment