android.webkit.WebSettings#setDatabaseEnabled ( )源码实例Demo

下面列出了android.webkit.WebSettings#setDatabaseEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tok-Android   文件: WebViewActivity.java
private void initSetting() {
    WebSettings settings = mWebView.getSettings();
    settings.setAppCacheEnabled(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    String userAgent = settings.getUserAgentString();
    settings.setUserAgentString(
        userAgent + " TokAndroid/" + String.valueOf(BuildConfig.VERSION_NAME));
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);
    settings.setDomStorageEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDatabaseEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
}
 
源代码2 项目: traccar-manager-android   文件: MainFragment.java
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if ((getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    getWebView().setWebViewClient(webViewClient);
    getWebView().setWebChromeClient(webChromeClient);
    getWebView().addJavascriptInterface(new AppInterface(), "appInterface");

    WebSettings webSettings = getWebView().getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setMediaPlaybackRequiresUserGesture(false);

    String url = PreferenceManager.getDefaultSharedPreferences(
            getActivity()).getString(MainActivity.PREFERENCE_URL, null);

    getWebView().loadUrl(url);
}
 
源代码3 项目: letv   文件: SocialApiIml.java
@SuppressLint({"SetJavaScriptEnabled"})
public void writeEncryToken(Context context) {
    String str = "tencent&sdk&qazxc***14969%%";
    String accessToken = this.mToken.getAccessToken();
    String appId = this.mToken.getAppId();
    String openId = this.mToken.getOpenId();
    String str2 = "qzone3.4";
    if (accessToken == null || accessToken.length() <= 0 || appId == null || appId.length() <= 0 || openId == null || openId.length() <= 0) {
        str = null;
    } else {
        str = Util.encrypt(str + accessToken + appId + openId + str2);
    }
    com.tencent.open.c.b bVar = new com.tencent.open.c.b(context);
    WebSettings settings = bVar.getSettings();
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    accessToken = "<!DOCTYPE HTML><html lang=\"en-US\"><head><meta charset=\"UTF-8\"><title>localStorage Test</title><script type=\"text/javascript\">document.domain = 'qq.com';localStorage[\"" + this.mToken.getOpenId() + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + this.mToken.getAppId() + "\"]=\"" + str + "\";</script></head><body></body></html>";
    str = ServerSetting.getInstance().getEnvUrl(context, ServerSetting.DEFAULT_LOCAL_STORAGE_URI);
    bVar.loadDataWithBaseURL(str, accessToken, "text/html", "utf-8", str);
}
 
源代码4 项目: letv   文件: PKDialog.java
@SuppressLint({"SetJavaScriptEnabled"})
private void initViews() {
    this.mWebView.setVerticalScrollBarEnabled(false);
    this.mWebView.setHorizontalScrollBarEnabled(false);
    this.mWebView.setWebViewClient(new FbWebViewClient());
    this.mWebView.setWebChromeClient(this.mChromeClient);
    this.mWebView.clearFormData();
    WebSettings settings = this.mWebView.getSettings();
    settings.setSavePassword(false);
    settings.setSaveFormData(false);
    settings.setCacheMode(-1);
    settings.setNeedInitialFocus(false);
    settings.setBuiltInZoomControls(true);
    settings.setSupportZoom(true);
    settings.setRenderPriority(RenderPriority.HIGH);
    settings.setJavaScriptEnabled(true);
    if (!(this.mWeakContext == null || this.mWeakContext.get() == null)) {
        settings.setDatabaseEnabled(true);
        settings.setDatabasePath(((Context) this.mWeakContext.get()).getApplicationContext().getDir("databases", 0).getPath());
    }
    settings.setDomStorageEnabled(true);
    this.jsBridge.a(new JsListener(), "sdk_js_if");
    this.mWebView.clearView();
    this.mWebView.loadUrl(this.mUrl);
    this.mWebView.getSettings().setSavePassword(false);
}
 
源代码5 项目: ZhuanLan   文件: CommonWebView.java
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);
}
 
源代码6 项目: mv-android-client   文件: WebPlayerView.java
private void init(Context context) {
    mPlayer = new WebPlayer(this);

    setBackgroundColor(Color.BLACK);

    enableJavascript();

    WebSettings webSettings = getSettings();
    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(context.getDir("database", Context.MODE_PRIVATE).getPath());
    webSettings.setDomStorageEnabled(true);
    webSettings.setLoadsImagesAutomatically(true);
    webSettings.setSupportMultipleWindows(true);

    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_MR1) {
            webSettings.setMediaPlaybackRequiresUserGesture(false);
        }
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
    }

    setWebChromeClient(new ChromeClient());
    setWebViewClient(new ViewClient());
}
 
void init() {

    setWebViewClient(new LoveClient());
    setWebChromeClient(new Chrome());
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSaveFormData(false);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setUseWideViewPort(true);
  }
 
源代码8 项目: letv   文件: CustomWebView.java
@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 项目: samples   文件: SnsPreviewActivity.java
@SuppressLint("SetJavaScriptEnabled")
private void settingWebView() {
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setMinimumFontSize(16);

    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(false);

    settings.setDatabaseEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);  //设置 缓存模式
    // 开启 DOM storage API 功能
    settings.setDomStorageEnabled(true);
}
 
源代码10 项目: WanAndroid   文件: ArticleActivity.java
/**
 * 配置WebView
 */
@SuppressLint("SetJavaScriptEnabled")
private void setSettings(WebSettings settings) {
    if (mPresenter.getNoImageState())
        settings.setBlockNetworkImage(true);
    else
        settings.setBlockNetworkImage(false);

    if(mPresenter.getAutoCacheState()){
        settings.setAppCacheEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setDatabaseEnabled(true);
        if(NetWorkUtil.isNetworkConnected(this))
            settings.setCacheMode(WebSettings.LOAD_DEFAULT);//(默认)根据cache-control决定是否从网络上取数据
        else
            settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//只要本地有,无论是否过期,或者no-cache,都使用缓存中的数据。
    }else {
        settings.setAppCacheEnabled(false);
        settings.setDatabaseEnabled(false);
        settings.setDatabaseEnabled(false);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不使用缓存,只从网络获取数据
    }

    //支持缩放
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    //不显示缩放按钮
    settings.setDisplayZoomControls(false);
    //设置自适应屏幕,两者合用
    //将图片调整到适合WebView的大小
    settings.setUseWideViewPort(true);
    //缩放至屏幕的大小
    settings.setLoadWithOverviewMode(true);
    //自适应屏幕
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
}
 
源代码11 项目: Ninja   文件: NinjaWebView.java
private synchronized void initWebSettings() {
    WebSettings webSettings = getSettings();
    userAgentOriginal = webSettings.getUserAgentString();

    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);

    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().toString());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setGeolocationDatabasePath(context.getFilesDir().toString());

    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webSettings.setLoadsImagesAutomatically(true);
    } else {
        webSettings.setLoadsImagesAutomatically(false);
    }
}
 
源代码12 项目: HelloActivityAndFragment   文件: Tab2Fragment.java
@SuppressLint("JavascriptInterface")
private void initWebView() {

    // Settings
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName("GBK");
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setGeolocationEnabled(true);
    // settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    settings.setDatabaseEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath());
    settings.setDisplayZoomControls(false);


    webView.requestFocus();

    webView.setWebViewClient(new WebViewClient() {
    });

    webView.setWebChromeClient(new WebChromeClient() {

    });

}
 
源代码13 项目: OsmGo   文件: Bridge.java
/**
 * Initialize the WebView, setting required flags
 */
private void initWebView() {
  WebSettings settings = webView.getSettings();
  settings.setJavaScriptEnabled(true);
  settings.setDomStorageEnabled(true);
  settings.setGeolocationEnabled(true);
  settings.setDatabaseEnabled(true);
  settings.setAppCacheEnabled(true);
  settings.setMediaPlaybackRequiresUserGesture(false);
  settings.setJavaScriptCanOpenWindowsAutomatically(true);
  if (Config.getBoolean("android.allowMixedContent", false)) {
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
  }
  String backgroundColor = Config.getString("android.backgroundColor" , Config.getString("backgroundColor", null));
  try {
    if (backgroundColor != null) {
      webView.setBackgroundColor(Color.parseColor(backgroundColor));
    }
  } catch (IllegalArgumentException ex) {
    Log.d(LogUtils.getCoreTag(), "WebView background color not applied");
  }
  boolean defaultDebuggable = false;
  if (isDevMode()) {
    defaultDebuggable = true;
  }

  WebView.setWebContentsDebuggingEnabled(Config.getBoolean("android.webContentsDebuggingEnabled", defaultDebuggable));
}
 
源代码14 项目: keemob   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
源代码15 项目: tysq-android   文件: BitWebViewFragment.java
private void initWebViewSetting(WebSettings settings) {

        //支持js脚本
        settings.setJavaScriptEnabled(true);
        //支持缩放
        settings.setSupportZoom(true);
        //支持缩放
        settings.setBuiltInZoomControls(true);
        //去除缩放按钮
        settings.setDisplayZoomControls(false);

        //扩大比例的缩放
        settings.setUseWideViewPort(true);
        //自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);

        //多窗口
        settings.supportMultipleWindows();
        //关闭webview中缓存
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        //设置可以访问文件
        settings.setAllowFileAccess(true);
        //当webview调用requestFocus时为webview设置节点
        settings.setNeedInitialFocus(true);
        //支持通过JS打开新窗口
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        //支持自动加载图片
        settings.setLoadsImagesAutomatically(true);

        //启用地理定位
//        settings.setGeolocationEnabled(true);
        //设置渲染优先级
        settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

        // 设置支持本地存储
        settings.setDatabaseEnabled(true);
        //设置支持DomStorage
        settings.setDomStorageEnabled(true);

        addJavascriptInterface();

    }
 
源代码16 项目: focus-android   文件: ClassicWebViewProvider.java
@SuppressLint("SetJavaScriptEnabled") // We explicitly want to enable JavaScript
private void configureDefaultSettings(Context context, WebSettings settings) {
    settings.setJavaScriptEnabled(true);

    // Needs to be enabled to display some HTML5 sites that use local storage
    settings.setDomStorageEnabled(true);

    // Enabling built in zooming shows the controls by default
    settings.setBuiltInZoomControls(true);

    // So we hide the controls after enabling zooming
    settings.setDisplayZoomControls(false);

    // To respect the html viewport:
    settings.setLoadWithOverviewMode(true);

    // Also increase text size to fill the viewport (this mirrors the behaviour of Firefox,
    // Chrome does this in the current Chrome Dev, but not Chrome release).
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);

    // Disable access to arbitrary local files by webpages - assets can still be loaded
    // via file:///android_asset/res, so at least error page images won't be blocked.
    settings.setAllowFileAccess(false);
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);

    final String appName = context.getResources().getString(R.string.useragent_appname);
    settings.setUserAgentString(buildUserAgentString(context, settings, appName));

    // Right now I do not know why we should allow loading content from a content provider
    settings.setAllowContentAccess(false);

    // The default for those settings should be "false" - But we want to be explicit.
    settings.setAppCacheEnabled(false);
    settings.setDatabaseEnabled(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(false);

    // We do not implement the callbacks - So let's disable it.
    settings.setGeolocationEnabled(false);

    // We do not want to save any data...
    settings.setSaveFormData(false);
    //noinspection deprecation - This method is deprecated but let's call it in case WebView implementations still obey it.
    settings.setSavePassword(false);
}
 
源代码17 项目: unity-ads-android   文件: WebView.java
public WebView(Context context) {
	super(context);
	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(true);
		settings.setAllowUniversalAccessFromFileURLs(true);
	}

	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setBlockNetworkImage(false);
	settings.setBlockNetworkLoads(false);
	settings.setBuiltInZoomControls(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setDisplayZoomControls(false);
	}

	settings.setDomStorageEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setEnableSmoothTransition(false);
	}

	settings.setGeolocationEnabled(false);
	settings.setJavaScriptCanOpenWindowsAutomatically(false);
	settings.setJavaScriptEnabled(true);
	settings.setLightTouchEnabled(false);
	settings.setLoadWithOverviewMode(false);
	settings.setLoadsImagesAutomatically(true);

	if(Build.VERSION.SDK_INT >= 17) {
		settings.setMediaPlaybackRequiresUserGesture(false);
	}

	if(Build.VERSION.SDK_INT >= 21) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}

	settings.setNeedInitialFocus(true);
	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);
	settings.setSupportMultipleWindows(false);
	settings.setSupportZoom(false);
	settings.setUseWideViewPort(true);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	addJavascriptInterface(new WebViewBridgeInterface(), "webviewbridge");
}
 
源代码18 项目: Awesome-WanAndroid   文件: ArticleDetailActivity.java
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void initEventAndData() {
    mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(mWebContent, new LinearLayout.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .setMainFrameErrorView(R.layout.webview_error_view, -1)
            .createAgentWeb()
            .ready()
            .go(articleLink);

    WebView mWebView = mAgentWeb.getWebCreator().getWebView();
    WebSettings mSettings = mWebView.getSettings();
    if (mPresenter.getNoImageState()) {
        mSettings.setBlockNetworkImage(true);
    } else {
        mSettings.setBlockNetworkImage(false);
    }
    if (mPresenter.getAutoCacheState()) {
        mSettings.setAppCacheEnabled(true);
        mSettings.setDomStorageEnabled(true);
        mSettings.setDatabaseEnabled(true);
        if (CommonUtils.isNetworkConnected()) {
            mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        } else {
            mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        }
    } else {
        mSettings.setAppCacheEnabled(false);
        mSettings.setDomStorageEnabled(false);
        mSettings.setDatabaseEnabled(false);
        mSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }

    mSettings.setJavaScriptEnabled(true);
    mSettings.setSupportZoom(true);
    mSettings.setBuiltInZoomControls(true);
    //不显示缩放按钮
    mSettings.setDisplayZoomControls(false);
    //设置自适应屏幕,两者合用
    //将图片调整到适合WebView的大小
    mSettings.setUseWideViewPort(true);
    //缩放至屏幕的大小
    mSettings.setLoadWithOverviewMode(true);
    //自适应屏幕
    mSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
}
 
源代码19 项目: letv   文件: AppbarActivity.java
private void initViews() {
    Method method;
    WebSettings settings = this.mWebView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setUserAgentString(settings.getUserAgentString() + "/" + UA_PREFIX + this.jsBridge.getVersion() + "/sdk");
    settings.setJavaScriptEnabled(true);
    Class cls = settings.getClass();
    try {
        method = cls.getMethod("setPluginsEnabled", new Class[]{Boolean.TYPE});
        if (method != null) {
            method.invoke(settings, new Object[]{Boolean.valueOf(true)});
        }
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (Throwable th) {
        th.printStackTrace();
    }
    try {
        method = cls.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
        if (method != null) {
            method.invoke(settings, new Object[]{Boolean.valueOf(true)});
        }
    } catch (SecurityException e2) {
        e2.printStackTrace();
    } catch (NoSuchMethodException e3) {
    } catch (IllegalArgumentException e4) {
    } catch (IllegalAccessException e5) {
    } catch (InvocationTargetException e6) {
    }
    settings.setAppCachePath(getWebViewCacheDir());
    settings.setDatabasePath(getWebViewCacheDir());
    settings.setDatabaseEnabled(true);
    settings.setAppCacheEnabled(true);
    if (supportWebViewFullScreen()) {
        settings.setUseWideViewPort(true);
        if (VERSION.SDK_INT >= 7) {
            try {
                cls.getMethod("setLoadWithOverviewMode", new Class[]{Boolean.TYPE}).invoke(settings, new Object[]{Boolean.valueOf(true)});
            } catch (Exception e7) {
            }
        }
        if (SystemUtils.isSupportMultiTouch()) {
            if (SystemUtils.getAndroidSDKVersion() < 11) {
                try {
                    Field declaredField = WebView.class.getDeclaredField("mZoomButtonsController");
                    declaredField.setAccessible(true);
                    ZoomButtonsController zoomButtonsController = new ZoomButtonsController(this.mWebView);
                    zoomButtonsController.getZoomControls().setVisibility(8);
                    declaredField.set(this.mWebView, zoomButtonsController);
                } catch (Exception e8) {
                }
            } else {
                try {
                    this.mWebView.getSettings().getClass().getMethod("setDisplayZoomControls", new Class[]{Boolean.TYPE}).invoke(this.mWebView.getSettings(), new Object[]{Boolean.valueOf(false)});
                } catch (Exception e9) {
                }
            }
        }
    }
    this.mWebView.setWebViewClient(new d());
    this.mWebView.setWebChromeClient(new c());
    this.mWebView.setDownloadListener(this.mDownloadListener);
    this.mWebView.loadUrl(this.url);
}
 
源代码20 项目: pychat   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}