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

下面列出了android.webkit.WebSettings#getUserAgentString ( ) 实例代码,或者点击链接到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 项目: Lucid-Browser   文件: CustomWebView.java
public void setDesktopMode(final boolean enabled) {
	final WebSettings webSettings = getSettings();

	if (origionalUserAgent==null) {
		origionalUserAgent = webSettings.getUserAgentString();
		Log.d("LB", "Your user agent is:"+origionalUserAgent);
	}

	String newUserAgent = origionalUserAgent;
	if (enabled) {
		try {
			String ua = webSettings.getUserAgentString();
			String androidOSString = webSettings.getUserAgentString().substring(ua.indexOf("("), ua.indexOf(")") + 1);
			newUserAgent = origionalUserAgent.replace(androidOSString,"(X11; Linux x86_64)");
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	else {
		newUserAgent = origionalUserAgent;
	}

	webSettings.setUserAgentString(newUserAgent);
	webSettings.setUseWideViewPort(enabled);
	webSettings.setLoadWithOverviewMode(enabled);
}
 
源代码3 项目: FastWaiMai   文件: WebViewInitializer.java
/**
 * 初始化传入的webView
 */
@SuppressLint("SetJavaScriptEnabled")
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public WebView initialWebView(WebView webView){
	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 项目: FastWebView   文件: InnerFastClient.java
InnerFastClient(FastWebView owner) {
    mOwner = owner;
    WebSettings settings = owner.getSettings();
    mWebViewCacheMode = settings.getCacheMode();
    mUserAgent = settings.getUserAgentString();
    mWebViewCache = new WebViewCacheImpl(owner.getContext());
}
 
源代码5 项目: dcs-sdk-java   文件: BaseWebView.java
@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());
}
 
源代码6 项目: focus-android   文件: ClassicWebViewProvider.java
private String buildUserAgentString(final Context context, final WebSettings settings, final String appName) {
    final StringBuilder uaBuilder = new StringBuilder();

    uaBuilder.append("Mozilla/5.0");

    // WebView by default includes "; wv" as part of the platform string, but we're a full browser
    // so we shouldn't include that.
    // Most webview based browsers (and chrome), include the device name AND build ID, e.g.
    // "Pixel XL Build/NOF26V", that seems unnecessary (and not great from a privacy perspective),
    // so we skip that too.
    uaBuilder.append(" (Linux; Android ").append(Build.VERSION.RELEASE).append(") ");

    final String existingWebViewUA = settings.getUserAgentString();

    final String appVersion;
    try {
        appVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        // This should be impossible - we should always be able to get information about ourselves:
        throw new IllegalStateException("Unable find package details for Focus", e);
    }

    final String focusToken = appName + "/" + appVersion;
    uaBuilder.append(getUABrowserString(existingWebViewUA, focusToken));

    return uaBuilder.toString();
}
 
源代码7 项目: focus-android   文件: ClassicWebViewProvider.java
private static String toggleDesktopUA(final WebSettings settings, final boolean requestDesktop) {
    final String existingUAString = settings.getUserAgentString();
    if (requestDesktop) {
        return existingUAString.replace("Mobile", "eliboM").replace("Android", "diordnA");
    } else {
        return existingUAString.replace("eliboM", "Mobile").replace("diordnA", "Android");
    }
}
 
源代码8 项目: SprintNBA   文件: HuPuWebView.java
private void init() {
    WebSettings settings = getSettings();
    settings.setBuiltInZoomControls(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setSupportMultipleWindows(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT > 6) {
        settings.setAppCacheEnabled(true);
        settings.setLoadWithOverviewMode(true);
    }
    String path = getContext().getFilesDir().getPath();
    settings.setGeolocationEnabled(true);
    settings.setGeolocationDatabasePath(path);
    settings.setDomStorageEnabled(true);
    this.basicUA = settings.getUserAgentString() + " kanqiu/7.05.6303/7059";
    setBackgroundColor(0);
    initWebViewClient();
    setWebChromeClient(new HuPuChromeClient());
    try {
        if (SettingPrefUtils.isLogin()) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "u=" + SettingPrefUtils.getCookies());
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_gamesu=" + URLEncoder.encode(SettingPrefUtils.getToken(), "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_inKanqiuApp=1");
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_kanqiu=1");
            CookieSyncManager.getInstance().sync();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码9 项目: phphub-android   文件: WebViewPageActivity.java
private String getUserAgent() {
    if (Build.VERSION.SDK_INT < 19) {
        WebView webView = new WebView(this);
        WebSettings settings = webView.getSettings();
        return settings.getUserAgentString();
    }

    // api >= 19
    return WebSettings.getDefaultUserAgent(this);
}
 
源代码10 项目: TLint   文件: HuPuWebView.java
private void init() {
    ((MyApplication) getContext().getApplicationContext()).getApplicationComponent().inject(this);
    WebSettings settings = getSettings();
    settings.setBuiltInZoomControls(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setSupportMultipleWindows(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(1);
    settings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT > 6) {
        settings.setAppCacheEnabled(true);
        settings.setLoadWithOverviewMode(true);
    }
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    String path = getContext().getFilesDir().getPath();
    settings.setGeolocationEnabled(true);
    settings.setGeolocationDatabasePath(path);
    settings.setDomStorageEnabled(true);
    this.basicUA = settings.getUserAgentString() + " kanqiu/7.05.6303/7059";
    setBackgroundColor(0);
    initWebViewClient();
    try {
        if (mUserStorage.isLogin()) {
            String token = mUserStorage.getToken();
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com",
                    "u=" + URLEncoder.encode(mUserStorage.getCookie(), "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com",
                    "_gamesu=" + URLEncoder.encode(token, "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_inKanqiuApp=1");
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_kanqiu=1");
            CookieSyncManager.getInstance().sync();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码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 项目: DevUtils   文件: WebViewAssist.java
/**
 * 获取浏览器标识 UA
 * @return 浏览器标识 UA
 */
public String getUserAgentString() {
    WebSettings webSettings = getSettings();
    return (webSettings != null) ? webSettings.getUserAgentString() : null;
}
 
源代码13 项目: lona   文件: 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
}
 
源代码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 项目: Android-Application-ZJB   文件: BaseWebFragment.java
protected void initialize() {
    //添加H5的基本参数
    UrlParserManager.getInstance().addParams(UrlParserManager.METHOD_CHANNEL, "app");
    mParamBuilder = getParams();
    mUrl = UrlParserManager.getInstance().parsePlaceholderUrl(mParamBuilder.getUrl());

    mWebView.setProgressbar(mProgressBar);
    WebSettings ws = mWebView.getSettings();
    ws.setBuiltInZoomControls(false); // 缩放
    ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    ws.setUseWideViewPort(true);
    ws.setLoadWithOverviewMode(true);
    ws.setSaveFormData(true);
    ws.setDomStorageEnabled(true);//开启 database storage API 功能
    //设置自定义UserAgent
    String agent = ws.getUserAgentString();
    ws.setUserAgentString(createUserAgent(agent));
    mWebView.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> {
        if (url != null && url.startsWith("http://"))
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    });
    mWebView.loadUrl(mUrl);
    mWebView.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            //表示按返回键时的操作
            if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
                mWebView.goBack();   //后退
                return true;    //已处理
            }
        }
        return false;
    });

    mWebView.setDefaultHandler(new DefaultHandler());
    //注册分享方法
    mWebView.registerHandler("shareJs", (data, function) -> {
        try {
            if (!TextUtils.isEmpty(data)) {
                WebShareBean shareBean = GsonUtil.fromJson(data, WebShareBean.class);
                shareJs(shareBean);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

    //注册设置标题方法
    mWebView.registerHandler("webTitleJs", ((data, function) -> webTitleJs(data)));
    //注册设置分享按钮方法
    mWebView.registerHandler("disableShareJs", ((data, function) -> {
        if ("true".equals(data)) {
            disableShareJs(true);
        } else {
            disableShareJs(false);
        }

    }));

    //注册微信支付
    mWebView.registerHandler("wxPayJs", ((data, function) -> wxPayJs(data)));
}
 
源代码16 项目: countly-sdk-cordova   文件: 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
}
 
源代码17 项目: 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
}
 
/**
 * 系统加载
 */
protected void systemLoader(Context context)
{
	if (RockySdk.getInstance().getContext() != null)
	{
		return;
	}
	
	Context application = context.getApplicationContext();
	
	// 用于获取浏览器代理
	WebView webview = new WebView(context);
	webview.layout(0, 0, 0, 0);
	WebSettings webSettings = webview.getSettings();
	
	ApplicationInfo applicationInfo = context.getApplicationInfo();
	
	VersionInfo versionInfo = ManifestTools.getVersionInfo(application);
	String userAgent = webSettings.getUserAgentString();
	
	// Structure the ClientInfo.
	ClientInfo clientInfo = new ClientInfo(application.getPackageName());
	//clientInfo.setAppicon(R.drawable.ic_launcher);
	clientInfo.setAppicon(applicationInfo.icon);
	clientInfo.setAppname(ManifestTools.getApplicationLable(application));
	clientInfo.setDeviceType(SdkConfig.Device.PHONE);
	clientInfo.setDeviceName(android.os.Build.MODEL);
	clientInfo.setAlias(android.os.Build.MODEL);
	clientInfo.setSdkVersion(android.os.Build.VERSION.SDK_INT);
	clientInfo.setMac(DeviceInfoManager.getMacAddress(application));
	
	// Webkit user-agent
	clientInfo.setUserAgent(userAgent);
	
	if (versionInfo != null)
	{
		clientInfo.setVersionCode(versionInfo.getVersionCode());
		clientInfo.setVersionName(versionInfo.getVersionName());
	}
	
	// FIXME: Take attention...
	clientInfo.addFlags(ClientInfo.FLAG_DEBUG | ClientInfo.FLAG_RELEASE);
	// clientContext.addFlags(ClientContext.FLAG_DEBUG);
	
	// TODO: 广告
	RockyConfig config = new RockyConfig.Builder(application)
		.clientInfo(clientInfo)
		.hasAdBanner(false)		// 显示积分Banner
		.hasAdPointsWall(true)	// 显示积分墙
		.build();
	
	RockySdk.getInstance().init(config);
}
 
源代码19 项目: android-project-wo2b   文件: Global.java
/**
 * 系统初始化
 * 
 * @param context
 */
public static void init(Context context)
{
	if (RockySdk.getInstance().getContext() != null)
	{
		return;
	}

	Context application = context.getApplicationContext();
	
	// 用于获取浏览器代理
	WebView webview = new WebView(context);
	webview.layout(0, 0, 0, 0);
	WebSettings webSettings = webview.getSettings();
	
	ApplicationInfo applicationInfo = context.getApplicationInfo();
	
	VersionInfo versionInfo = ManifestTools.getVersionInfo(application);
	String userAgent = webSettings.getUserAgentString();
	
	// Structure the ClientInfo.
	ClientInfo clientInfo = new ClientInfo(application.getPackageName());
	//clientInfo.setAppicon(R.drawable.ic_launcher);
	clientInfo.setAppicon(applicationInfo.icon);
	clientInfo.setAppname(ManifestTools.getApplicationLable(application));
	clientInfo.setDeviceType(SdkConfig.Device.PHONE);
	clientInfo.setDeviceName(android.os.Build.MODEL);
	clientInfo.setAlias(android.os.Build.MODEL);
	clientInfo.setSdkVersion(android.os.Build.VERSION.SDK_INT);
	clientInfo.setMac(DeviceInfoManager.getMacAddress(application));
	
	// Webkit user-agent
	clientInfo.setUserAgent(userAgent);
	
	if (versionInfo != null)
	{
		clientInfo.setVersionCode(versionInfo.getVersionCode());
		clientInfo.setVersionName(versionInfo.getVersionName());
	}
	
	// FIXME: Take attention...
	clientInfo.addFlags(ClientInfo.FLAG_DEBUG | ClientInfo.FLAG_RELEASE);
	// clientContext.addFlags(ClientContext.FLAG_DEBUG);
	
	// TODO: 广告
	RockyConfig config = new RockyConfig.Builder(application)
		.clientInfo(clientInfo)
		.hasAdBanner(false)		// 显示积分Banner
		.hasAdPointsWall(true)	// 显示积分墙
		.build();
	
	RockySdk.getInstance().init(config);
}
 
源代码20 项目: Android_Skin_2.0   文件: WebSettingsCompat.java
@Override
public String getUserAgentString(WebSettings settings) {
	return settings.getUserAgentString();
}