gpt4 book ai didi

android - 用户代理中的 'mobile' 关键字来自哪里?

转载 作者:行者123 更新时间:2023-11-30 00:38:29 24 4
gpt4 key购买 nike

我很困惑,在Android系统的移动设备(phone)上,基于chromium的浏览器(例如webview)的useragentMobile关键字,但是在某些移动设备上(例如tablets)是不存在的,那么在chrmoium代码中区分在哪里呢?

具有Mobile关键字的移动设备:

"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"

最佳答案

也许您可以查看并引用 DeviceUtils.javaaw_content_client.cc在 Chromium 源中,它将通过 DeviceFormFactor.isTablet()DeviceUtils.java 中检查设备类型决定是否需要添加Mobile关键字,在aw_content_client.cc中设置Mobile关键字,希望这些信息可以帮助到您:

//DeviceUtils.java
package org.chromium.content.browser;

import android.content.Context;

import org.chromium.base.CommandLine;
import org.chromium.content.common.ContentSwitches;
import org.chromium.ui.base.DeviceFormFactor;

/**
* A utility class that has helper methods for device configuration.
*/
public class DeviceUtils {

/**
* Appends the switch specifying which user agent should be used for this device.
* @param context The context for the caller activity.
*/
public static void addDeviceSpecificUserAgentSwitch(Context context) {
if (DeviceFormFactor.isTablet(context)) {
CommandLine.getInstance().appendSwitch(ContentSwitches.USE_MOBILE_UA);
}
}
}



//aw_content_client.cc
std::string GetUserAgent() {
// "Version/4.0" had been hardcoded in the legacy WebView.
std::string product = "Version/4.0 " + GetProduct();
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseMobileUserAgent)) {
product += " Mobile";
}
return content::BuildUserAgentFromProductAndExtraOSInfo(
product,
GetExtraOSUserAgentInfo());
}

关于android - 用户代理中的 'mobile' 关键字来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com