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


Java WebSettings.getUserAgentString方法代码示例

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


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

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * 添加user_agent
 */
public void addUserAgent() {
    // 原来是通过cookie还设置服务器所需的参数,但服务器在接收时会非常麻烦
    // 现通过修改user_agent还设置服务器所需的参数,服务器可直接获取
    WebSettings websettings = webView.getSettings();
    String user_agent = websettings.getUserAgentString();
    //// TODO: 16/11/1
    user_agent = Config.FORMAT_USER_AGENT;
    // demo/3.6.2 (android; extension txt; extension txt)
    String addAgent = " demo/"
            + PhoneInfoUtil.getInstance().getVersion(context)
            + "(android; extension txt; extension txt)";
    String newUserAgent;
    //如果不包含 添加
    if (!user_agent.contains(addAgent)) {
        newUserAgent = user_agent + addAgent;
    } else {
        newUserAgent = user_agent;
    }
    websettings.setUserAgentString(newUserAgent);
}
 
开发者ID:AlpacaNotSheep,项目名称:hybrid,代码行数:24,代码来源:IndexWebActivityNew.java

示例3: getUserAgent

import android.webkit.WebSettings; //导入方法依赖的package包/类
public static String getUserAgent(Context context) {
    String userAgent = null;
    WebView webView = new WebView(context);
    WebSettings settings = webView.getSettings();
    if (settings != null) {
        userAgent = settings.getUserAgentString();
    }
    return userAgent;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:StrUtils.java

示例4: 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

示例5: settingWebView

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * 初始化设置
 */
public void settingWebView() {
    WebSettings settings = getSettings();
    String ua = settings.getUserAgentString();
    // 设置浏览器UA,JS端通过UA判断是否属于Quick环境
    settings.setUserAgentString(ua + " QuickHybridJs/" + BuildConfig.VERSION_NAME);
    // 设置支持JS
    settings.setJavaScriptEnabled(true);
    // 设置是否支持meta标签来控制缩放
    settings.setUseWideViewPort(true);
    // 缩放至屏幕的大小
    settings.setLoadWithOverviewMode(true);
    // 设置内置的缩放控件(若SupportZoom为false,该设置项无效)
    settings.setBuiltInZoomControls(true);
    // 设置缓存模式
    // LOAD_DEFAULT 根据HTTP协议header中设置的cache-control属性来执行加载策略
    // LOAD_CACHE_ELSE_NETWORK 只要本地有无论是否过期都从本地获取
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDomStorageEnabled(true);
    // 设置AppCache 需要H5页面配置manifest文件(官方已不推介使用)
    String appCachePath = getContext().getCacheDir().getAbsolutePath();
    settings.setAppCachePath(appCachePath);
    settings.setAppCacheEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // 强制开启android webview debug模式使用Chrome inspect(https://developers.google.com/web/tools/chrome-devtools/remote-debugging/)
        WebView.setWebContentsDebuggingEnabled(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
    }
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:34,代码来源:QuickWebView.java

示例6: init

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * 系统初始化
 * 
 * @param context
 */
public static void init(Context context)
{
	if (CDK.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 CDKContext.
	CDKContext cdkContext = new CDKContext(application.getPackageName());
	//clientInfo.setAppicon(R.drawable.ic_launcher);
	cdkContext.setAppicon(applicationInfo.icon);
	cdkContext.setAppname(ManifestTools.getApplicationLable(application));
	cdkContext.setDeviceType(CDKConfig.Device.PHONE);
	cdkContext.setAlias(android.os.Build.MODEL);
	cdkContext.setAndroidSdkVersion(android.os.Build.VERSION.SDK_INT);
	cdkContext.setMac(DeviceInfoManager.getMacAddress(application));
	
	// Webkit user-agent
	cdkContext.setUserAgent(userAgent);
	
	if (versionInfo != null)
	{
		cdkContext.setAppVersionCode(versionInfo.getVersionCode());
		cdkContext.setAppVersionName(versionInfo.getVersionName());
	}
	
	// FIXME: Take attention...
	cdkContext.addFlags(CDKContext.FLAG_DEBUG | CDKContext.FLAG_RELEASE);
	// cdkContext.addFlags(CDKContext.FLAG_DEBUG);
	
	// TODO: 广告
	CDKConfig config = new CDKConfig.Builder(application)
		.cdkContext(cdkContext)
		.hasAdBanner(false)		// 显示积分Banner
		.hasAdPointsWall(true)	// 显示积分墙
		.build();
	
	CDK.getInstance().init(config);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:57,代码来源:Global.java

示例7: systemLoader

import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
 * 系统加载
 */
protected void systemLoader(Context context)
{
	if (CDK.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 CDKContext.
	CDKContext cdkContext = new CDKContext(application.getPackageName());
	//clientInfo.setAppicon(R.drawable.ic_launcher);
	cdkContext.setAppicon(applicationInfo.icon);
	cdkContext.setAppname(ManifestTools.getApplicationLable(application));
	cdkContext.setDeviceType(CDKConfig.Device.PHONE);
	cdkContext.setAlias(android.os.Build.MODEL);
	cdkContext.setAndroidSdkVersion(android.os.Build.VERSION.SDK_INT);
	cdkContext.setMac(DeviceInfoManager.getMacAddress(application));
	
	// Webkit user-agent
	cdkContext.setUserAgent(userAgent);
	
	if (versionInfo != null)
	{
		cdkContext.setAppVersionCode(versionInfo.getVersionCode());
		cdkContext.setAppVersionName(versionInfo.getVersionName());
	}
	
	// FIXME: Take attention...
	cdkContext.addFlags(CDKContext.FLAG_DEBUG | CDKContext.FLAG_RELEASE);
	// cdkContext.addFlags(CDKContext.FLAG_DEBUG);
	
	// TODO: 广告
	CDKConfig config = new CDKConfig.Builder(application)
		.cdkContext(cdkContext)
		.hasAdBanner(false)		// 显示积分Banner
		.hasAdPointsWall(true)	// 显示积分墙
		.build();
	
	CDK.getInstance().init(config);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:55,代码来源:BaseFragmentActivity.java


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