当前位置: 首页>>代码示例>>Java>>正文


Java WebSettings.setUserAgentString方法代码示例

本文整理汇总了Java中android.webkit.WebSettings.setUserAgentString方法的典型用法代码示例。如果您正苦于以下问题:Java WebSettings.setUserAgentString方法的具体用法?Java WebSettings.setUserAgentString怎么用?Java WebSettings.setUserAgentString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.webkit.WebSettings的用法示例。


在下文中一共展示了WebSettings.setUserAgentString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:remerber,项目名称:FastEc,代码行数:41,代码来源:WebViewInitializer.java

示例2: init

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void init(Context context) {
    this.setVerticalScrollBarEnabled(false);
    this.setHorizontalScrollBarEnabled(false);
    if (Build.VERSION.SDK_INT < 19) {
        removeJavascriptInterface("searchBoxJavaBridge_");
    }

    WebSettings localWebSettings = this.getSettings();
    try {
        // 禁用file协议,http://www.tuicool.com/articles/Q36ZfuF, 防止Android WebView File域攻击
        localWebSettings.setAllowFileAccess(false);
        localWebSettings.setSupportZoom(false);
        localWebSettings.setBuiltInZoomControls(false);
        localWebSettings.setUseWideViewPort(true);
        localWebSettings.setDomStorageEnabled(true);
        localWebSettings.setLoadWithOverviewMode(true);
        localWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        localWebSettings.setPluginState(PluginState.ON);
        // 启用数据库
        localWebSettings.setDatabaseEnabled(true);
        // 设置定位的数据库路径
        String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        localWebSettings.setGeolocationDatabasePath(dir);
        localWebSettings.setGeolocationEnabled(true);
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setSavePassword(false);
        String agent = localWebSettings.getUserAgentString();

        localWebSettings.setUserAgentString(agent);
        // setCookie(context, ".baidu.com", bdussCookie);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    this.setWebViewClient(new BridgeWebViewClient());
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:39,代码来源:BaseWebView.java

示例3: initWebView

import android.webkit.WebSettings; //导入方法依赖的package包/类
public void initWebView(WebView webView) {
        webView.setVerticalScrollBarEnabled(false);
        webView.setBackgroundColor(getResources().getColor(R.color.white));
        //设置webview的配置
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        WebSettings webseting = webView.getSettings();
        // 支持JavaScript
        webseting.setJavaScriptEnabled(true);
        // 支持保存数据
        webseting.setSaveFormData(false);
        webseting.setDomStorageEnabled(true);
//		webseting.setAppCacheMaxSize(1024 * 1024 * 8);// 设置缓冲大小,我设的是8M
        String appCacheDir = getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
        webseting.setAppCachePath(appCacheDir);
        webseting.setUserAgentString(Config.FORMAT_USER_AGENT);
        webseting.setLoadWithOverviewMode(true);
        webseting.setUseWideViewPort(true);
        webseting.setDatabaseEnabled(true);
        webseting.setAllowFileAccess(true);
        webseting.setCacheMode(WebSettings.LOAD_DEFAULT);
        /*强制webview使用标准字号大小*/
        webseting.setTextZoom(100);

        // webseting.setBlockNetworkImage(true);
        webseting.setLoadsImagesAutomatically(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webView.setWebContentsDebuggingEnabled(true);// Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.
        }

        //移除webkit内部存在安全漏洞的javascript接口
        webView.removeJavascriptInterface("searchBoxJavaBridge_");
        webView.removeJavascriptInterface("accessibility");
        webView.removeJavascriptInterface("accessibilityTraversal");

    }
 
开发者ID:AlpacaNotSheep,项目名称:hybrid,代码行数:38,代码来源:BaseWebActivity.java

示例4: setDesktopMode

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * Force web sites to show their desktop versions
 * @param enabled false loads the mobile version
 */
public void setDesktopMode(boolean enabled) {
    WebSettings webSettings = getSettings();
    String newUserAgent;
    if (enabled)
        newUserAgent = webSettings.getUserAgentString().replace("Mobile", "eliboM").replace("Android", "diordnA");
    else
        newUserAgent = webSettings.getUserAgentString().replace("eliboM", "Mobile").replace("diordnA", "Android");
    webSettings.setUserAgentString(newUserAgent);
    webSettings.setUseWideViewPort(enabled);
    webSettings.setLoadWithOverviewMode(enabled);
    webSettings.setSupportZoom(enabled);
    webSettings.setBuiltInZoomControls(enabled);
}
 
开发者ID:vic797,项目名称:prowebview,代码行数:18,代码来源:ProWebView.java

示例5: WebViewTask

import android.webkit.WebSettings; //导入方法依赖的package包/类
public WebViewTask(Context context) {
    webView = new WebView(context);
    webView.addJavascriptInterface(new InJavaScriptLocalObj(), "get_source");
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            webView.loadUrl("javascript:window.get_source.getSource('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
        }
    });
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setBlockNetworkImage(true);
    webSettings.setUserAgentString("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36");
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:16,代码来源:WebViewTask.java

示例6: 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();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:33,代码来源:CustomWebView.java

示例7: onCreate

import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    setContentView(R.layout.activity_web);
    name = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_NAME);
    url = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_URL);
    color = getIntent().getExtras().getInt(Common.WEBVIEW_EXTRA_COLOR);
    needsLogin = getIntent().getExtras().getBoolean(Common.WEBVIEW_EXTRA_NLOGIN);
    //Action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setNavigationBarColor(color);
        getWindow().setStatusBarColor(color);
    }
    app = (App) getApplication();

    TextView title = (TextView) findViewById(R.id.toolbar_title);
    title.setText(name);

    progress = (ProgressBar) findViewById(R.id.web_progressBar);
    webView = (WebView) findViewById(R.id.webView);

    if (savedInstanceState != null) {
        progress.setVisibility(View.INVISIBLE);
        webView.setVisibility(View.VISIBLE);
        webView.restoreState(savedInstanceState);
    }
    else {
        progress.setVisibility(View.VISIBLE);
        webView.setWebViewClient(new WebViewClient());
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUserAgentString("IEMobile");
        startControllers();
    }

}
 
开发者ID:Onelio,项目名称:ConnectU,代码行数:41,代码来源:WebActivity.java

示例8: onCreate

import android.webkit.WebSettings; //导入方法依赖的package包/类
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        try {
            String string = extras.getString("url");
            if (k.a(string)) {
                Method method;
                super.requestWindowFeature(1);
                this.c = new Handler(getMainLooper());
                Object string2 = extras.getString("cookie");
                if (!TextUtils.isEmpty(string2)) {
                    CookieSyncManager.createInstance(getApplicationContext()).sync();
                    CookieManager.getInstance().setCookie(string, string2);
                    CookieSyncManager.getInstance().sync();
                }
                View linearLayout = new LinearLayout(getApplicationContext());
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                linearLayout.setOrientation(1);
                setContentView(linearLayout, layoutParams);
                this.a = new WebView(getApplicationContext());
                layoutParams.weight = 1.0f;
                this.a.setVisibility(0);
                linearLayout.addView(this.a, layoutParams);
                WebSettings settings = this.a.getSettings();
                settings.setUserAgentString(settings.getUserAgentString() + k.c(getApplicationContext()));
                settings.setRenderPriority(RenderPriority.HIGH);
                settings.setSupportMultipleWindows(true);
                settings.setJavaScriptEnabled(true);
                settings.setSavePassword(false);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
                settings.setAllowFileAccess(false);
                settings.setTextSize(TextSize.NORMAL);
                this.a.setVerticalScrollbarOverlay(true);
                this.a.setWebViewClient(new a());
                this.a.loadUrl(string);
                if (VERSION.SDK_INT >= 7) {
                    try {
                        method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                        if (method != null) {
                            method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
                        }
                    } catch (Exception e) {
                    }
                }
                try {
                    method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
                    if (method != null) {
                        method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
                        return;
                    }
                    return;
                } catch (Exception e2) {
                    return;
                }
            }
            finish();
        } catch (Exception e3) {
            finish();
        }
    } catch (Exception e4) {
        finish();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:70,代码来源:H5PayActivity.java

示例9: onCreate

import android.webkit.WebSettings; //导入方法依赖的package包/类
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        try {
            this.d = extras.getString(b);
            String string = extras.getString("params");
            if (k.a(string)) {
                Method method;
                super.requestWindowFeature(1);
                this.f = new Handler(getMainLooper());
                View linearLayout = new LinearLayout(getApplicationContext());
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                linearLayout.setOrientation(1);
                setContentView(linearLayout, layoutParams);
                this.c = new WebView(getApplicationContext());
                layoutParams.weight = 1.0f;
                this.c.setVisibility(0);
                linearLayout.addView(this.c, layoutParams);
                WebSettings settings = this.c.getSettings();
                settings.setUserAgentString(settings.getUserAgentString() + k.c(getApplicationContext()));
                settings.setRenderPriority(RenderPriority.HIGH);
                settings.setSupportMultipleWindows(true);
                settings.setJavaScriptEnabled(true);
                settings.setSavePassword(false);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
                settings.setAllowFileAccess(false);
                settings.setTextSize(TextSize.NORMAL);
                this.c.setVerticalScrollbarOverlay(true);
                this.c.setWebViewClient(new b());
                this.c.setWebChromeClient(new a());
                this.c.setDownloadListener(new a(this));
                this.c.loadUrl(string);
                if (VERSION.SDK_INT >= 7) {
                    try {
                        method = this.c.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                        if (method != null) {
                            method.invoke(this.c.getSettings(), new Object[]{Boolean.valueOf(true)});
                        }
                    } catch (Exception e) {
                    }
                }
                try {
                    method = this.c.getClass().getMethod("removeJavascriptInterface", new Class[0]);
                    if (method != null) {
                        method.invoke(this.c, new Object[]{"searchBoxJavaBridge_"});
                        return;
                    }
                    return;
                } catch (Exception e2) {
                    return;
                }
            }
            finish();
        } catch (Exception e3) {
            finish();
        }
    } catch (Exception e4) {
        finish();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:67,代码来源:AuthActivity.java

示例10: initWebView

import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebView() {
    final WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true); // needed for FxA login.
    webView.setWebViewClient(new ScriptInjectionWebViewClient(script));

    final String userAgent = FirefoxDataRequestUtils.getUserAgent(applicationName, DeviceUtils.isTablet());
    webSettings.setUserAgentString(userAgent);

    // It's recommended JS interface is used on SDK min 17+ because on earlier versions the
    // page's JS can use reflection to call Java methods. However, since we trust the page,
    // we shouldn't be vulnerable.
    webView.addJavascriptInterface(new JSInterface(), JS_INTERFACE_OBJ);
    webView.loadUrl(webViewURL);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:FirefoxDataWebViewLoginActivity.java

示例11: initWebSettings

import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
public void initWebSettings(WebSettings webSettings){
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUserAgentString("ios");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}
 
开发者ID:flyer88,项目名称:EasyJsBridge,代码行数:14,代码来源:MainActivity.java

示例12: onCreate

import android.webkit.WebSettings; //导入方法依赖的package包/类
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        try {
            String string = extras.getString("url");
            if (i.b(string)) {
                Method method;
                super.requestWindowFeature(1);
                this.c = new Handler(getMainLooper());
                View linearLayout = new LinearLayout(getApplicationContext());
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                linearLayout.setOrientation(1);
                setContentView(linearLayout, layoutParams);
                this.a = new WebView(getApplicationContext());
                layoutParams.weight = 1.0f;
                this.a.setVisibility(0);
                linearLayout.addView(this.a, layoutParams);
                WebSettings settings = this.a.getSettings();
                settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
                settings.setRenderPriority(RenderPriority.HIGH);
                settings.setSupportMultipleWindows(true);
                settings.setJavaScriptEnabled(true);
                settings.setSavePassword(false);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
                settings.setAllowFileAccess(false);
                settings.setTextSize(TextSize.NORMAL);
                this.a.setVerticalScrollbarOverlay(true);
                this.a.setWebViewClient(new a());
                this.a.setDownloadListener(new b(this));
                this.a.loadUrl(string);
                if (VERSION.SDK_INT >= 7) {
                    try {
                        method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                        if (method != null) {
                            method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
                        }
                    } catch (Exception e) {
                    }
                }
                try {
                    method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
                    if (method != null) {
                        method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
                        method.invoke(this.a, new Object[]{"accessibility"});
                        method.invoke(this.a, new Object[]{"accessibilityTraversal"});
                        return;
                    }
                    return;
                } catch (Exception e2) {
                    return;
                }
            }
            finish();
        } catch (Exception e3) {
            finish();
        }
    } catch (Exception e4) {
        finish();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:67,代码来源:H5AuthActivity.java

示例13: onCreate

import android.webkit.WebSettings; //导入方法依赖的package包/类
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        try {
            String string = extras.getString("url");
            if (i.b(string)) {
                Method method;
                super.requestWindowFeature(1);
                this.c = new Handler(getMainLooper());
                Object string2 = extras.getString("cookie");
                if (!TextUtils.isEmpty(string2)) {
                    CookieSyncManager.createInstance(getApplicationContext()).sync();
                    CookieManager.getInstance().setCookie(string, string2);
                    CookieSyncManager.getInstance().sync();
                }
                View linearLayout = new LinearLayout(getApplicationContext());
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                linearLayout.setOrientation(1);
                setContentView(linearLayout, layoutParams);
                this.a = new WebView(getApplicationContext());
                layoutParams.weight = 1.0f;
                this.a.setVisibility(0);
                linearLayout.addView(this.a, layoutParams);
                WebSettings settings = this.a.getSettings();
                settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
                settings.setRenderPriority(RenderPriority.HIGH);
                settings.setSupportMultipleWindows(true);
                settings.setJavaScriptEnabled(true);
                settings.setSavePassword(false);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
                settings.setAllowFileAccess(false);
                settings.setTextSize(TextSize.NORMAL);
                this.a.setVerticalScrollbarOverlay(true);
                this.a.setWebViewClient(new a());
                this.a.loadUrl(string);
                if (VERSION.SDK_INT >= 7) {
                    try {
                        method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                        if (method != null) {
                            method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
                        }
                    } catch (Exception e) {
                    }
                }
                try {
                    method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
                    if (method != null) {
                        method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
                        method.invoke(this.a, new Object[]{"accessibility"});
                        method.invoke(this.a, new Object[]{"accessibilityTraversal"});
                        return;
                    }
                    return;
                } catch (Exception e2) {
                    return;
                }
            }
            finish();
        } catch (Exception e3) {
            finish();
        }
    } catch (Exception e4) {
        finish();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:72,代码来源:H5PayActivity.java

示例14: onCreate

import android.webkit.WebSettings; //导入方法依赖的package包/类
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        try {
            this.d = extras.getString(b);
            String string = extras.getString("params");
            if (i.b(string)) {
                Method method;
                super.requestWindowFeature(1);
                this.f = new Handler(getMainLooper());
                View linearLayout = new LinearLayout(getApplicationContext());
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                linearLayout.setOrientation(1);
                setContentView(linearLayout, layoutParams);
                this.c = new WebView(getApplicationContext());
                layoutParams.weight = 1.0f;
                this.c.setVisibility(0);
                linearLayout.addView(this.c, layoutParams);
                WebSettings settings = this.c.getSettings();
                settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
                settings.setRenderPriority(RenderPriority.HIGH);
                settings.setSupportMultipleWindows(true);
                settings.setJavaScriptEnabled(true);
                settings.setSavePassword(false);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
                settings.setAllowFileAccess(false);
                settings.setTextSize(TextSize.NORMAL);
                this.c.setVerticalScrollbarOverlay(true);
                this.c.setWebViewClient(new b());
                this.c.setWebChromeClient(new a());
                this.c.setDownloadListener(new a(this));
                this.c.loadUrl(string);
                if (VERSION.SDK_INT >= 7) {
                    try {
                        method = this.c.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                        if (method != null) {
                            method.invoke(this.c.getSettings(), new Object[]{Boolean.valueOf(true)});
                        }
                    } catch (Exception e) {
                    }
                }
                try {
                    method = this.c.getClass().getMethod("removeJavascriptInterface", new Class[0]);
                    if (method != null) {
                        method.invoke(this.c, new Object[]{"searchBoxJavaBridge_"});
                        method.invoke(this.c, new Object[]{"accessibility"});
                        method.invoke(this.c, new Object[]{"accessibilityTraversal"});
                        return;
                    }
                    return;
                } catch (Exception e2) {
                    return;
                }
            }
            finish();
        } catch (Exception e3) {
            finish();
        }
    } catch (Exception e4) {
        finish();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:69,代码来源:AuthActivity.java

示例15: setUserAgent

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * This method sets the user agent of the current tab.
 * There are four options, 1, 2, 3, 4.
 * <p/>
 * 1. use the default user agent
 * <p/>
 * 2. use the desktop user agent
 * <p/>
 * 3. use the mobile user agent
 * <p/>
 * 4. use a custom user agent, or the default user agent
 * if none was set.
 *
 * @param context the context needed to get the default user agent.
 * @param choice  the choice of user agent to use, see above comments.
 */
@SuppressLint("NewApi")
private void setUserAgent(Context context, int choice) {
    if (mWebView == null) return;
    WebSettings settings = mWebView.getSettings();
    switch (choice) {
        case 1:
            if (API >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                settings.setUserAgentString(WebSettings.getDefaultUserAgent(context));
            } else {
                settings.setUserAgentString(sDefaultUserAgent);
            }
            break;
        case 2:
            settings.setUserAgentString(Constants.DESKTOP_USER_AGENT);
            break;
        case 3:
            settings.setUserAgentString(Constants.MOBILE_USER_AGENT);
            break;
        case 4:
            String ua = mPreferences.getUserAgentString(sDefaultUserAgent);
            if (ua == null || ua.isEmpty()) {
                ua = " ";
            }
            settings.setUserAgentString(ua);
            break;
    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:44,代码来源:LightningView.java


注:本文中的android.webkit.WebSettings.setUserAgentString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。