本文整理了Java中android.webkit.WebSettings.setAppCachePath()
方法的一些代码示例,展示了WebSettings.setAppCachePath()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSettings.setAppCachePath()
方法的具体详情如下:
包路径:android.webkit.WebSettings
类名称:WebSettings
方法名:setAppCachePath
暂无
代码示例来源:origin: hidroh/materialistic
private void enableCache() {
WebSettings webSettings = getSettings();
webSettings.setAppCacheEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCachePath(getContext().getApplicationContext()
.getCacheDir().getAbsolutePath());
setCacheModeInternal();
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* A webview setting which enable JavaScript ,DomStorage and file access.
* @param webView
* @param appCacheDir
* @return
*/
public static WebSettings getWebSettings(WebView webView, String appCacheDir) {
WebSettings wSet = webView.getSettings();
// wSet.setAppCacheMaxSize();
wSet.setJavaScriptEnabled(true);
wSet.setDomStorageEnabled(true);
// String appCacheDir = this.getActivity().getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
wSet.setAppCachePath(appCacheDir);
wSet.setAllowFileAccess(true);
wSet.setAppCacheEnabled(true);
wSet.setCacheMode(WebSettings.LOAD_DEFAULT);
return wSet;
}
代码示例来源:origin: xinghongfei/LookLook
private void initView() {
mToolbar.setTitleMargin(20,20,0,10);
mToolbar.setNavigationIcon(R.drawable.ic_arrow_back);
mToolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mNest.smoothScrollTo(0,0);
}
});
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandImageAndFinish();
}
});
mTranslateYTextView.setText(title);
WebSettings settings = wvZhihu.getSettings();
settings.setJavaScriptEnabled(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
//settings.setUseWideViewPort(true);造成文字太小
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache");
settings.setAppCacheEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
wvZhihu.setWebChromeClient(new WebChromeClient());
}
代码示例来源:origin: TheFinestArtist/FinestWebView-Android
settings.setAppCachePath(webViewAppCachePath);
代码示例来源:origin: Justson/AgentWeb
mWebSettings.setAppCachePath(dir);
代码示例来源:origin: wendux/DSBridge-Android
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
private void init() {
APP_CACHE_DIRNAME = getContext().getFilesDir().getAbsolutePath() + "/webcache";
WebSettings settings = getSettings();
settings.setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
settings.setAllowFileAccess(false);
settings.setAppCacheEnabled(false);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setAppCachePath(APP_CACHE_DIRNAME);
settings.setUseWideViewPort(true);
super.setWebChromeClient(mWebChromeClient);
addInternalJavascriptObject();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
super.addJavascriptInterface(innerJavascriptInterface, BRIDGE_NAME);
} else {
// add dsbridge tag in lower android version
settings.setUserAgentString(settings.getUserAgentString() + " _dsbridge");
}
}
代码示例来源:origin: com.novoda/notils
private void enableCaching() {
webView.getSettings().setAppCachePath(getFilesDir() + getPackageName() + "/cache");
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
}
代码示例来源:origin: bkhezry/ExtraWebView
private void enableCache() {
WebSettings webSettings = getSettings();
webSettings.setAppCacheEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCachePath(getContext().getApplicationContext()
.getCacheDir().getAbsolutePath());
}
代码示例来源:origin: mnnyang/ClassSchedule
/**
* HTML5数据存储
*/
private void saveData(WebSettings mWebSettings) {
//有时候网页需要自己保存一些关键数据,Android WebView 需要自己设置
mWebSettings.setDomStorageEnabled(true);
mWebSettings.setDatabaseEnabled(true);
mWebSettings.setAppCacheEnabled(true);
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
mWebSettings.setAppCachePath(appCachePath);
}
代码示例来源:origin: stackoverflow.com
WebView view;
... //initialize WebView
WebSettings webViewSettings = view.getSettings();
view.setWebChromeClient(new WebChromeClient(){}); //just added this
webViewSettings.setDomStorageEnabled(true);
webViewSettings.setAppCacheEnabled(true);
webViewSettings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webViewSettings.setDatabaseEnabled(true);
webViewSettings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
代码示例来源:origin: stackoverflow.com
webView.setInitialScale(0);
webView.setVerticalScrollBarEnabled(false);
// Enable JavaScript
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
// Enable AppCache
// Fix for CB-2282
settings.setAppCacheMaxSize(5 * 1048576);
settings.setAppCachePath(databasePath);
settings.setAppCacheEnabled(true);
代码示例来源:origin: free46000/HybridFoundation
private void setCache(WebSettings settings) {
settings.setCacheMode(WebSettings.LOAD_DEFAULT);//默认的缓存使用模式。在进行页面前进或后退的操作时,如果缓存可用并未过期就优先加载缓存,否则从网络上加载数据。这样可以减少页面的网络请求次数
File cacheDir = getContext().getCacheDir();
settings.setDomStorageEnabled(true);
if (cacheDir != null) {
String appCachePath = cacheDir.getAbsolutePath();
settings.setDatabaseEnabled(true);
settings.setAppCacheEnabled(true);
settings.setDatabasePath(appCachePath);
settings.setAppCachePath(appCachePath);
}
}
代码示例来源:origin: stackoverflow.com
final WebSettings webviewSettings = webView.getSettings();
final String appCachePath = this.getCacheDir().getAbsolutePath();
webviewSettings.setDomStorageEnabled(true);
webviewSettings.setAppCachePath(appCachePath);
webviewSettings.setAllowFileAccess(true);
webviewSettings.setAppCacheEnabled(true);
webviewSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
代码示例来源:origin: Lovemma/ZhihuDaily
private void initWebView() {
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setSupportZoom(false);
settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache");
settings.setAppCacheEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mWebView.setWebChromeClient(new WebChromeClient());
}
代码示例来源:origin: stackoverflow.com
Webview kWebview = new Webview(context);
kWebview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
kWebview.setFocusable(false);
kWebview.setClickable(false);
kWebview.setLongClickable(false);
kWebview.setFocusableInTouchMode(false);
kWebview.setInitialScale(100);
kWebview.setBackgroundColor(Color.BLACK);
WebSettings kSet = kWebview.getSettings();
kSet.setLoadWithOverviewMode(false);
kSet.setLoadsImagesAutomatically(true);
kSet.setAppCacheEnabled(true);
kSet.setAppCachePath(_context.getCacheDir().toString());
kSet.setCacheMode(WebSettings.LOAD_DEFAULT);
kSet.setAllowFileAccess(true);
kSet.setDomStorageEnabled(true);
kWebview.loadUrl("http://image_url");
代码示例来源:origin: stackoverflow.com
public void importPhoneGapUser() {
String databasePath = getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
String pathToCache = getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
WebView mAuthWebView = new WebView(this);
WebSettings webSettings = mAuthWebView.getSettings();
webSettings.setDatabasePath(databasePath);
webSettings.setAppCachePath(pathToCache);
webSettings.setGeolocationDatabasePath(databasePath);
webSettings.setAppCacheMaxSize(5 * 1048576);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
mAuthWebView.addJavascriptInterface(new MyJavaScriptInterface (), "JsInterface");
//i wasn't able to run JS through 'javascript:' protocol, so i had to use a HTML file
mAuthWebView.loadUrl("file:///android_asset/import_auth.html");
}
代码示例来源:origin: Lovemma/ZhihuDaily
private void initWebView() {
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setSupportZoom(false);
settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache");
settings.setAppCacheEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mWebView.setWebChromeClient(new WebChromeClient());
}
}
代码示例来源:origin: WhiteDG/BihuDaily
@Override
protected void initView() {
initToolbar(R.string.editor_info_title);
WebSettings webSettings = webEditor.getSettings();
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCachePath(getApplicationContext().getDir("cache", 0).getPath());
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically(true);
}
代码示例来源:origin: WhiteDG/BihuDaily
@SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
@Override
protected void initView() {
initToolbar();
setToolbarTitle("");
WebSettings webSettings = webContent.getSettings();
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCachePath(getApplicationContext().getDir("cache", 0).getPath());
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically(true);
// 调用js
webContent.addJavascriptInterface(this, "BihuDaily");
}
代码示例来源:origin: bxbxbai/ZhuanLan
private void init() {
if (isInEditMode()) {
return;
}
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(false);
//设置缓存模式
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//开启DOM storage API功能
settings.setDomStorageEnabled(true);
//开启database storage 功能
settings.setDatabaseEnabled(true);
String cacheDir = getContext().getFilesDir().getAbsolutePath() + "web_cache";
settings.setAppCachePath(cacheDir);
settings.setAppCacheEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setDefaultTextEncodingName(ENCODING_UTF_8);
settings.setBlockNetworkImage(false);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
setHorizontalScrollBarEnabled(false);
}
}
内容来源于网络,如有侵权,请联系作者删除!