java - Change the user agent of Crosswalk 13+ as webview in Cordova -


i trying change user agent of crosswalk used webview cordova. using plugin cordova-plugin-crosswalk-webview.

i able accomplish customization of user agent vanilla cordova following code:

import android.webkit.websettings; import android.webkit.webview;  public class mainactivity extends cordovaactivity {         public websettings settings;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         super.init();          settings = ((webview) super.appview.getengine().getview()).getsettings();         string defaultua = settings.getuseragentstring();         string customua = defaultua+" oreeganoc1";         settings.setuseragentstring(customua);          loadurl(launchurl);     } } 

however, when run app crosswalk plugin crashes due piece of code. works without crosswalk. using cordova 5.2.0 , crosswalk 13.

any hints?

i'm not sure if preferred method or not, here's did (using crosswalk 14+):

  1. i added custom preference config.xml:

    <preference name="xwalkuseragent" value="custom ua" />

  2. in project/platforms/android/src/org/crosswalk/engine/xwalkwebviewengine.java, added following code inside class:

    public static final string pref_user_agent = "xwalkuseragent"; protected cordovapreferences preferences; 

    in constructor, stored preferences:

    public xwalkwebviewengine(context context, cordovapreferences preferences) {     this.preferences = preferences;     ... } 

    finally, in initwebviewsettings() method, set user agent:

    private void initwebviewsettings() {     webview.setverticalscrollbarenabled(false);     string xwalkuseragent = preferences.getstring(pref_user_agent, "");     webview.setuseragentstring(xwalkuseragent); } 

now whenever need change user agent, can config.xml.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -