您的位置:首页 > 移动开发 > Android开发

Android webview如何打开本地存储,提供给JS调用html5的lwindow.localStorage功能

2013-07-26 15:56 495 查看
mWebView = (WebView) this.findViewById(R.id.webview);

		WebSettings settings = mWebView.getSettings();
		settings.setJavaScriptEnabled(true);
		//settings.setPluginsEnabled(true);

		
		/***打开本地缓存提供JS调用**/
		mWebView.getSettings().setDomStorageEnabled(true);
	    // Set cache size to 8 mb by default. should be more than enough
		mWebView.getSettings().setAppCacheMaxSize(1024*1024*8);
	    // This next one is crazy. It's the DEFAULT location for your app's cache
	    // But it didn't work for me without this line.
	    // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
	    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
	    mWebView.getSettings().setAppCachePath(appCachePath);
	    mWebView.getSettings().setAllowFileAccess(true);
	    mWebView.getSettings().setAppCacheEnabled(true);


java的navtive代码只要设置了以上参数,就可以为JS端提供本地存储了,记住这个参数需要API>=7使用,也就是android2.1版本以上才可以。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: