0

I am new to all of this, so I am probably missing something pretty obvious, but I am trying to change the userAgent string in an application I am building with Cordova. Based upon the documentation at the Cordova website, it would appear that I should only need to add the following to my config.xml file:

preference name="OverrideUserAgent" value="My string value here"

So I included this line in my config.xml and then added this code to my javascript in my cordova app:

var ua = navigator.userAgent;

alert(ua);

I then build the project and install it on my android phone. However, when I run the app I get the same userAgent reported back by my alert regardless of whether I included preference name="OverrideUserAgent" value="My string value here" in the config.xml or not. I am using version 5 of Cordova (5.3.1 I believe) and this config.xml fix was listed in the documentation for version 5.1.1 on the Cordova website.

I have also seen another possible fix on stackoverflow in the following post:

Change PhoneGap / Cordova User-Agent for AJAX

Specifically I am looking at the response that recommends:

put this in your onCreate method: (after super.init();) super.appView.getSettings().setUserAgentString("Your own agent string");

I am sorry to ask such a basic question, but how to I carry this out? Is it possible to do this while still using the Cordova CLI or do I need to import the project into Android studio first? Where exactly do I find the onCreate method that I need to modify.

Thank you for any help you may be able to offer.

Community
  • 1
  • 1
Jim
  • 1
  • 1
  • how apps have you done? It appears while you are taking the right steps, you have not read the correct pieces of documentation. –  Oct 25 '15 at 21:04
  • try waiting for deviceready event before checking the user agent – jcesarmobile Oct 26 '15 at 08:56
  • jcesamible: I added the following code and still the same result: document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { alert(navigator.userAgent); } I am pretty sure the problem is that I am not doing this using the in app browser, but in the body of the main app. I think that I need to go the second route mentioned in my post, which means I need to modify the onCreate method. – Jim Oct 26 '15 at 23:34

0 Answers0