How to chanage Crosswalk useragent string?


#1

Hi there!
I found this snippet on crosswalk website its changes an UserAgent string of webview.

XWalkView mXWalkView;
mXWalkView.getSettings().setUserAgentString("Your User Agent");

How can I use it with ionic project with crosswalk browser?
Please suggest me to add a snippet to right place.


#2

From your ionic project folder go to: engine/cordova-crosswalk-engine-xxxx\src\android\XWalkCordovaView.java

Override following lines

    public XWalkCordovaView(Context context, CordovaPreferences preferences) {
    super(setGlobalPrefs(context, preferences), (AttributeSet)null);
}

public XWalkCordovaView(Context context, AttributeSet attrs) {
    super(setGlobalPrefs(context, null), attrs);
}

with:

    public XWalkCordovaView(Context context, CordovaPreferences preferences) {
    super(setGlobalPrefs(context, preferences), (AttributeSet)null);
    this.getSettings().setUserAgentString("Your User Agent");
}

public XWalkCordovaView(Context context, AttributeSet attrs) {
    super(setGlobalPrefs(context, null), attrs);
    this.getSettings().setUserAgentString("Your User Agent");
}

This should do the trick.


#3

Thank you very much for herlp!
I found this java at

MyAppPath\plugins\cordova-plugin-crosswalk-webview\platforms\android\src\org\crosswalk\engine

Trying to build. Will write about result later


#5

Not successfull… Errors on compiling

  symbol: method getSettings()

E:\newapp\SamAptekaXwalk\platforms\android\src\org\crosswalk\engine\XWalkCordova
View.java:54: error: cannot find symbol
this.getSettings().setUserAgentString(“SamApteka Application”);
^
symbol: method getSettings()
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: E:\newapp\SamAptekaXwalk\platforms\android\src\org\apache\cordova\file\Ass
etFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors