本文整理汇总了Java中android.webkit.WebSettings.setAppCacheEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java WebSettings.setAppCacheEnabled方法的具体用法?Java WebSettings.setAppCacheEnabled怎么用?Java WebSettings.setAppCacheEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebSettings
的用法示例。
在下文中一共展示了WebSettings.setAppCacheEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setWebSettings
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void setWebSettings() {
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);//开启对JavaScript的支持
settings.setDefaultTextEncodingName("UTF-8");//设置字符编码
settings.setSupportZoom(true);
// 开启alert
settings.setJavaScriptCanOpenWindowsAutomatically(true);
// 开启按钮按下显示
settings.setLightTouchEnabled(true);
// settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setAppCacheEnabled(false);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
appendUserAgent("version", AppUtils.getNoPrefixVersionName(this));
mWebView.requestFocus();
mWebView.setWebChromeClient(chromeClient);
mWebView.setWebViewClient(webViewClient);
}
示例2: initWidgets
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
protected void initWidgets() {
super.initWidgets();
mBackImg = (ImageView) findViewById(R.id.kf5_return_img);
mBackImg.setOnClickListener(this);
mWebView = (WebView) findViewById(R.id.kf5_post_detail_content);
mDetailTitle = (TextView) findViewById(R.id.kf5_post_detail_title);
mDate = (TextView) findViewById(R.id.kf5_post_detail_date);
WebSettings webSettings = mWebView.getSettings();
webSettings.setBuiltInZoomControls(false);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setBuiltInZoomControls(false); //显示放大缩小 controler
webSettings.setSupportZoom(false); //可以缩放
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mWebView.setWebViewClient(new MyWebViewClient());
}
示例3: createWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
public WebView createWebView(WebView webView) {
//WebView.setWebContentsDebuggingEnabled(true);
//不能横向滚动
webView.setHorizontalScrollBarEnabled(false);
//不能纵向滚动
webView.setVerticalScrollBarEnabled(false);
//允许截图
webView.setDrawingCacheEnabled(true);
//屏蔽长按事件
webView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
//初始化WebSettings
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
final String ua = settings.getUserAgentString();
settings.setUserAgentString(ua + "Latte");
//隐藏缩放控件
settings.setBuiltInZoomControls(false);
settings.setDisplayZoomControls(false);
//禁止缩放
settings.setSupportZoom(false);
//文件权限
settings.setAllowFileAccess(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setAllowContentAccess(true);
//缓存相关
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
return webView;
}
示例4: initWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebView() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
/*使webview能够加载图片*/
webSettings.setBlockNetworkImage(false);
webSettings.setAppCacheEnabled(true);
mDialog=new SpotsDialog(this);
mDialog.show();
mWebView.loadUrl(mMessage.getClickUrl());
// mWebAppInterface = new WebAppInterface(this);
// mWebView.addJavascriptInterface(mWebAppInterface, "appInterface");
mWebView.setWebViewClient(new MyWebChromeC());
mWebView.setWebChromeClient(new WebChromeClient(){
});
}
示例5: init
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void init(Context context) {
mPlayer = new WebPlayer(this);
setBackgroundColor(Color.BLACK);
enableJavascript();
WebSettings webSettings = getSettings();
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDatabasePath(context.getDir("database", Context.MODE_PRIVATE).getPath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
}
setWebChromeClient(new ChromeClient());
setWebViewClient(new ViewClient());
}
示例6: initWebSettings
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebSettings() {
WebSettings settings = mWebView.getSettings();
//支持获取手势焦点
mWebView.requestFocusFromTouch();
//支持JS
settings.setJavaScriptEnabled(true);
//支持插件
settings.setPluginState(WebSettings.PluginState.ON);
//设置适应屏幕
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
//支持缩放
settings.setSupportZoom(false);
//隐藏原生的缩放控件
settings.setDisplayZoomControls(false);
//支持内容重新布局
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.supportMultipleWindows();
settings.setSupportMultipleWindows(true);
//设置缓存模式
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAppCacheEnabled(true);
settings.setAppCachePath(mWebView.getContext().getCacheDir().getAbsolutePath());
//设置可访问文件
settings.setAllowFileAccess(true);
//当webview调用requestFocus时为webview设置节点
settings.setNeedInitialFocus(true);
//支持自动加载图片
if (Build.VERSION.SDK_INT >= 19) {
settings.setLoadsImagesAutomatically(true);
} else {
settings.setLoadsImagesAutomatically(false);
}
settings.setNeedInitialFocus(true);
//设置编码格式
settings.setDefaultTextEncodingName("UTF-8");
}
示例7: setupWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void setupWebView(WebSettings settings) {
if (settings == null) {
return;
}
settings.setAppCacheEnabled(true);
settings.setAllowFileAccess(true);
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setSupportZoom(true);
settings.setDisplayZoomControls(true);
}
示例8: initializeOptions
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"SetJavaScriptEnabled", "NewApi"})
public void initializeOptions() {
WebSettings settings = getSettings();
if (VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
}
settings.setUserAgentString(OtherUtil.getUserAgent(this.mContext));
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setCacheMode(2);
settings.setAllowFileAccess(true);
settings.setDefaultTextEncodingName("utf-8");
settings.setAppCacheEnabled(true);
settings.setGeolocationEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setLoadsImagesAutomatically(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setSaveFormData(true);
CookieManager.getInstance().setAcceptCookie(true);
setLongClickable(false);
setScrollbarFadingEnabled(true);
setScrollBarStyle(0);
setDrawingCacheEnabled(true);
setClickable(true);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
requestFocus();
}
示例9: enableCache
import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
* Function to enable caching
*/
private void enableCache() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB
webSettings.setAppCachePath(getContext().getCacheDir().getAbsolutePath());
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
if (!AppUtils.isNetworkConnected(getContext())) { // loading offline
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
}
示例10: onCreate
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceBundle) {
super.onCreate(savedInstanceBundle);
setContentView(R.layout.li_login_activity);
Intent intent = getIntent();
Toolbar toolbar = (Toolbar) findViewById(R.id.li_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
service = new LiAuthServiceImpl(this);
webViewOauth = (WebView) findViewById(R.id.li_web_oauth);
progBar = (ProgressBar) findViewById(R.id.li_login_page_prog_bar);
loginInProgTxt = (TextView) findViewById(R.id.li_login_in_prog_txt);
String authUrl = intent.getData().toString();
progBar.setVisibility(View.VISIBLE);
webViewOauth.setVisibility(View.INVISIBLE);
loginInProgTxt.setText(getString(R.string.li_openingLoginPage));
loginInProgTxt.setVisibility(View.VISIBLE);
isAccessTokenSaved = false;
webViewOauth.clearHistory();
webViewOauth.clearFormData();
webViewOauth.clearCache(true);
setTitle(authUrl);
//set the web client
webViewOauth.setWebViewClient(new LoginWebViewClient());
webViewOauth.setWebChromeClient(new LoginWebChromeClient());
//activates JavaScript (just in case)
WebSettings webSettings = webViewOauth.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAppCacheEnabled(false);
//load the url of the oAuth login page
webViewOauth.loadUrl(authUrl);
}
示例11: init
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
private void init(AttributeSet attrs) {
if (attrs != null) {
TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.CodeWebView);
try {
backgroundColor = tp.getColor(R.styleable.CodeWebView_webview_background,
ViewUtils.getWindowBackground(getContext()));
setBackgroundColor(backgroundColor);
} finally {
tp.recycle();
}
}
setWebChromeClient(new ChromeClient());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setWebViewClient(new WebClientN());
} else {
setWebViewClient(new WebClient());
}
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCachePath(getContext().getCacheDir().getPath());
settings.setAppCacheEnabled(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setDefaultTextEncodingName("utf-8");
settings.setLoadsImagesAutomatically(true);
settings.setBlockNetworkImage(false);
setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
WebView.HitTestResult result = getHitTestResult();
if (hitLinkResult(result) && !StringUtils.isBlank(result.getExtra())) {
AppUtils.copyToClipboard(getContext(), result.getExtra());
return true;
}
return false;
}
});
}
示例12: initWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebView() {
WebSettings ws = mWebView.getSettings();
// 网页内容的宽度是否可大于WebView控件的宽度
ws.setLoadWithOverviewMode(false);
// 保存表单数据
ws.setSaveFormData(true);
// 是否应该支持使用其屏幕缩放控件和手势缩放
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
ws.setDisplayZoomControls(false);
// 启动应用缓存
ws.setAppCacheEnabled(true);
// 设置缓存模式
ws.setCacheMode(WebSettings.LOAD_DEFAULT);
// setDefaultZoom api19被弃用
// 设置此属性,可任意比例缩放。
ws.setUseWideViewPort(true);
// 缩放比例 1
mWebView.setInitialScale(1);
// 告诉WebView启用JavaScript执行。默认的是false。
ws.setJavaScriptEnabled(true);
// 页面加载好以后,再放开图片
ws.setBlockNetworkImage(false);
// 使用localStorage则必须打开
ws.setDomStorageEnabled(true);
// 排版适应屏幕
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多个窗口。
ws.setSupportMultipleWindows(true);
// webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 设置字体默认缩放大小(改变网页字体大小,setTextSize api14被弃用)*/
ws.setTextZoom(100);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(webChromeClient = new MyWebChromeClient());
mWebView.loadUrl(url);
}
示例13: b
import android.webkit.WebSettings; //导入方法依赖的package包/类
private boolean b() {
this.b = (WebView) this.d.findViewById(ResContainer.getResourceId(this.k, ResType.ID,
"webView"));
this.b.setWebViewClient(c());
this.b.setWebChromeClient(new p(this));
this.b.requestFocusFromTouch();
this.b.setVerticalScrollBarEnabled(false);
this.b.setHorizontalScrollBarEnabled(false);
this.b.setScrollBarStyle(0);
this.b.getSettings().setCacheMode(2);
WebSettings settings = this.b.getSettings();
settings.setJavaScriptEnabled(true);
if (VERSION.SDK_INT >= 8) {
settings.setPluginState(PluginState.ON);
}
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setAllowFileAccess(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
settings.setUseWideViewPort(true);
if (VERSION.SDK_INT >= 8) {
settings.setLoadWithOverviewMode(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setGeolocationEnabled(true);
settings.setAppCacheEnabled(true);
}
if (VERSION.SDK_INT >= 11) {
try {
Method declaredMethod = WebSettings.class.getDeclaredMethod
("setDisplayZoomControls", new Class[]{Boolean.TYPE});
declaredMethod.setAccessible(true);
declaredMethod.invoke(settings, new Object[]{Boolean.valueOf(false)});
} catch (Exception e) {
}
}
try {
if (this.m == SHARE_MEDIA.RENREN) {
CookieSyncManager.createInstance(this.k);
CookieManager.getInstance().removeAllCookie();
}
} catch (Exception e2) {
}
return true;
}
示例14: init
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void init(Context context) {
mContext = context;
mLayout = new FrameLayout(context);
mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(context)
.inflate(R.layout.common_custom_screen, null);
wv_imgbtn_back = (LinearLayout) mBrowserFrameLayout.findViewById(R.id.top_bar_linear_back);
wv_tv_title = (TextView) mBrowserFrameLayout.findViewById(R.id.top_bar_title);
mContentView = (FrameLayout) mBrowserFrameLayout
.findViewById(R.id.main_content);
mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
.findViewById(R.id.fullscreen_custom_content);
frame_progress = (FrameLayout) mBrowserFrameLayout
.findViewById(R.id.frame_progress);
webview_tv_progress = (TextView) frame_progress
.findViewById(R.id.webview_tv_progress);
final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER);
mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
mWebChromeClient = new MyWebChromeClient();
setWebChromeClient(mWebChromeClient);
setWebViewClient(new MyWebViewClient());
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true); //开启javascript
webSettings.setDomStorageEnabled(true); //开启DOM
webSettings.setDefaultTextEncodingName("utf-8"); //设置编码
// // web页面处理
webSettings.setAllowFileAccess(true);// 支持文件流
// webSettings.setSupportZoom(true);// 支持缩放
// webSettings.setBuiltInZoomControls(true);// 支持缩放
webSettings.setUseWideViewPort(true);// 调整到适合webview大小
webSettings.setLoadWithOverviewMode(true);// 调整到适合webview大小
webSettings.setDefaultZoom(ZoomDensity.FAR);// 屏幕自适应网页,如果没有这个,在低分辨率的手机上显示可能会异常
webSettings.setRenderPriority(RenderPriority.HIGH);
//提高网页加载速度,暂时阻塞图片加载,然后网页加载好了,在进行加载图片
webSettings.setBlockNetworkImage(true);
//开启缓存机制
webSettings.setAppCacheEnabled(true);
//根据当前网页连接状态
if(StrUtils.getAPNType(context)== StrUtils.WIFI){
//设置无缓存
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
}else{
//设置缓存
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
mContentView.addView(this);
// 返回
wv_imgbtn_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
closeAdWebPage();
}
});
}
示例15: initWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebView() {
mProgressBar.setVisibility(View.VISIBLE);
WebSettings ws = webView.getSettings();
// 网页内容的宽度是否可大于WebView控件的宽度
ws.setLoadWithOverviewMode(false);
// 保存表单数据
ws.setSaveFormData(true);
// 是否应该支持使用其屏幕缩放控件和手势缩放
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
ws.setDisplayZoomControls(false);
// 启动应用缓存
ws.setAppCacheEnabled(true);
// 设置缓存模式
ws.setCacheMode(WebSettings.LOAD_DEFAULT);
// setDefaultZoom api19被弃用
// 设置此属性,可任意比例缩放。
ws.setUseWideViewPort(true);
// 缩放比例 1
webView.setInitialScale(1);
// 告诉WebView启用JavaScript执行。默认的是false。
ws.setJavaScriptEnabled(true);
// 页面加载好以后,再放开图片
ws.setBlockNetworkImage(false);
// 使用localStorage则必须打开
ws.setDomStorageEnabled(true);
// 排版适应屏幕
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多个窗口。
ws.setSupportMultipleWindows(true);
// webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 设置字体默认缩放大小(改变网页字体大小,setTextSize api14被弃用)*/
ws.setTextZoom(100);
mWebChromeClient = new MyWebChromeClient(this);
webView.setWebChromeClient(mWebChromeClient);
// 与js交互
webView.addJavascriptInterface(new ImageClickInterface(this), "injectedObject");
webView.setWebViewClient(new MyWebViewClient(this));
}