本文整理汇总了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();
}
}
}
示例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();
}
示例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);
}
示例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);
}
示例5: getDefaultUA
import android.webkit.WebSettings; //导入方法依赖的package包/类
private String getDefaultUA(Context context) {
return WebSettings.getDefaultUserAgent(context);
}