當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSettings.getDefaultUserAgent方法代碼示例

本文整理匯總了Java中android.webkit.WebSettings.getDefaultUserAgent方法的典型用法代碼示例。如果您正苦於以下問題:Java WebSettings.getDefaultUserAgent方法的具體用法?Java WebSettings.getDefaultUserAgent怎麽用?Java WebSettings.getDefaultUserAgent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.webkit.WebSettings的用法示例。


在下文中一共展示了WebSettings.getDefaultUserAgent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUserAgent

import android.webkit.WebSettings; //導入方法依賴的package包/類
@UiThread
public static String getUserAgent(@NonNull final Context context) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    return WebSettings.getDefaultUserAgent(context);
  } else {
    try {
      final Class<?> webSettingsClassicClass = Class.forName("android.webkit.WebSettingsClassic");
      final Constructor<?> constructor = webSettingsClassicClass
          .getDeclaredConstructor(Context.class, Class.forName("android.webkit.WebViewClassic"));
      constructor.setAccessible(true);
      final Method method = webSettingsClassicClass.getMethod("getUserAgentString");
      return (String) method.invoke(constructor.newInstance(context, null));
    } catch (final Exception e) {
      return new WebView(context).getSettings()
          .getUserAgentString();
    }
  }
}
 
開發者ID:azmedien,項目名稱:kolibri-android,代碼行數:19,代碼來源:KolibriApp.java

示例2: getUserAgent

import android.webkit.WebSettings; //導入方法依賴的package包/類
/**
 * 獲取UserAgent
 *
 * @return UserAgent
 */
@NonNull
public static String getUserAgent() {
    String userAgent = "";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        try {
            userAgent = WebSettings.getDefaultUserAgent(AppUtils.getContext());
        } catch (Exception e) {
            userAgent = System.getProperty("http.agent");
        }
    } else {
        userAgent = System.getProperty("http.agent");
    }
    StringBuffer sb = new StringBuffer();
    for (int i = 0, length = userAgent.length(); i < length; i++) {
        char c = userAgent.charAt(i);
        if (c <= '\u001f' || c >= '\u007f') {
            sb.append(String.format("\\u%04x", (int) c));
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}
 
開發者ID:Horrarndoo,項目名稱:YiZhi,代碼行數:29,代碼來源:HttpUtils.java

示例3: getDefaultUserAgent

import android.webkit.WebSettings; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private String getDefaultUserAgent(Context context)
{
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
  {
    // SDK version 17 and greater support new method to query for user-agent
    return WebSettings.getDefaultUserAgent(context);
  }
  
  // Older SDK versions can use the older way of retrieving the user agent
  return System.getProperty(SYSTEM_USER_AGENT_PROPERTY_KEY);
}
 
開發者ID:SOASTA,項目名稱:touchtestweb-android,代碼行數:13,代碼來源:MainActivity.java

示例4: onCreate

import android.webkit.WebSettings; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    sContext = this;
    preference = new Preference(this);

    AttackSetting.migrate();
    SmingManager.migrate();

    sUserAgent = WebSettings.getDefaultUserAgent(this);
}
 
開發者ID:monthlypub,項目名稱:SmingZZick_App,代碼行數:12,代碼來源:SmingApplication.java

示例5: getDefaultUA

import android.webkit.WebSettings; //導入方法依賴的package包/類
private String getDefaultUA(Context context) {
    return WebSettings.getDefaultUserAgent(context);
}
 
開發者ID:JaeNuguid,項目名稱:Kids-Portal-Android,代碼行數:4,代碼來源:Utils_UserAgent.java


注:本文中的android.webkit.WebSettings.getDefaultUserAgent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。