4

How can I set the HTTP_ACCEPT_LANGUAGE header with CrossWalk?

I've tried looking for the same methods as the original Android webview (like described here: How can I override Android WebView to use custom Accept-Language header?) but no luck.

The normal webview sends the correct header, CrossWalk however doesn't include my native language, just 'en-US'.

Community
  • 1
  • 1
dthomasen
  • 826
  • 15
  • 32

2 Answers2

1

I ended up editing the source, and then compiling from scratch.

If you want to do the same, the file to look in is "xwalk/runtime/browser/runtime_url_request_context_getter.cc"

Link to the file on Github

And then look for this:

storage_->set_http_user_agent_settings( 
new net::StaticHttpUserAgentSettings("da-DK,da;q=0.8,en-US;q=0.6,en;q=0.4", base::EmptyString()));

In this we added the "da-DK,da;q=0.8", but you get the idea.

How to build Crosswalk from source

dthomasen
  • 826
  • 15
  • 32
  • 1
    So NIce! It is better to send pull request to github. Yesterday I resolve it in another way. In my case, the `XWalkResourceClient` is used to intercept http access by `shouldInterceptLoadRequest` method. In this method, we can use `URLConnection` instead of `XWalkView`'s http connection and add any http headers freely. And it returns back `WebResourceResponse` in order to give the response to `XWalkView`. – KNaito Mar 26 '15 at 06:11
1

I had the same problem. I found out that the following beta version 15.44.384.8 accounts for this problem. So if you feel comfortable by using a beta version, you can find it here:

https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library_beta/

When using version 15.44.384.8 crosswalk will automatically select the language of your device settings.

You can add this version by modifing you build.gradle as follows:

repositories {
    maven {
        url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
    }
}


dependencies {
    ...other stuff...
    compile 'org.xwalk:xwalk_core_library_beta:15.44.384.8'
}
toom
  • 12,864
  • 27
  • 89
  • 128