I use the below code as many posts suggest to modify the user agent string the CordovaWebView will use. However I never receive this user agent string in any of the http requests to the server. I get the usual user agent string.
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;
}
I'm loading a GWT application from the server into an Android Cordova container. The GWT host page specifies a cache manifest. The call to the server for the cache manifest from the CordovaWebView does not contain the modified user agent string.
Any ideas why not?
I'm trying to detect whether the application is running in a Cordova container or the mobile browser by analyzing the user agent string received on the server so that I can serve up the correct cache manifest.
I am Looking for the same solution. For now I found the following options.
It seems the dev are working on feature that will enable it safely.
If you cant wait there is another way.
Update - My temp solution until CB-3360 is out
To change the User Agent I edited the file: CDVViewController.m at line 614 (on IOS)
From:
_userAgent = [NSString stringWithFormat:@"%@ (%lld)", localBaseUserAgent, (long long)self];
to:
_userAgent = [NSString stringWithFormat:@"%@ (%lld) MY EXTRA STRING", localBaseUserAgent, (long long)self];