我使用下面的代码,因为许多帖子建议修改CordovaWebView将使用的用户代理字符串。但是,我从未在任何对服务器的http请求中收到此用户代理字符串。我得到了通常的用户代理字符串。
public class MainActivity extends CordovaActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
CordovaWebView.setWebContentsDebuggingEnabled(true);
loadUrl(launchUrl);
}
@Override
protected CordovaWebView makeWebView() {
CordovaWebView cordovaWebView = super.makeWebView();
WebSettings settings = cordovaWebView.getSettings();
settings.setUserAgentString(settings.getUserAgentString()+" phonegap.env=yes");
settings.setAppCacheEnabled(true);
settings.setAppCachePath(getApplicationContext().getDir("html5-cache",MODE_PRIVATE).getAbsolutePath());
return cordovaWebView;
}
我正在从服务器将GWT应用程序加载到Android Cordova容器中。 GWT主机页面指定缓存清单。从CordovaWebView调用服务器以获取缓存清单不包含已修改的用户代理字符串。
任何想法为什么不呢?
我正在尝试通过分析服务器上收到的用户代理字符串来检测应用程序是在Cordova容器还是移动浏览器中运行,以便我可以提供正确的缓存清单。
答案 0 :(得分:1)
我正在寻找相同的解决方案。现在我找到了以下选项。
似乎开发人员正在使用feature来安全地启用它。
如果你不能等,有another way。
更新 - 我的临时解决方案,直到CB-3360结束
更改用户代理我编辑了文件:CDVViewController.m在第614行(在IOS上)
自:
_userAgent = [NSString stringWithFormat:@"%@ (%lld)", localBaseUserAgent, (long long)self];
为:
_userAgent = [NSString stringWithFormat:@"%@ (%lld) MY EXTRA STRING", localBaseUserAgent, (long long)self];