获取用户的android语言 [英] Get the language of user in android

查看:167
本文介绍了获取用户的android语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href="http://web.archiveorange.com/archive/v/fwvde0wN3xcViMtADw6x">http://web.archiveorange.com/archive/v/fwvde0wN3xcViMtADw6x

看来navigator.language属性始终是恩中的WebView的机器人。那么,什么是得到用户的语言的最佳方法是什么?得到它在本地的Java code和被JavaScript倒入的WebView?或任何其他更好的办法?

It seems that navigator.language property is always "en" in webview on androids. Then, what is the best way to get the language of user? Get it in native java code and pour it into webview by javascript? or any other better way?

推荐答案

我发现这个问题的解决方案是通过web视图的设置来设置用户代理:

The solution I found to this problem is to set the user agent through the webview's settings:

WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUserAgentString(Locale.getDefault().getLanguage());

在你的WebContent你再通过检索它:

In your webcontent you then retrieve it through:

var userLang = navigator.userAgent;

这应该仅用于显示本地内容的web视图。

This should only be used for a webview displaying local content.

这篇关于获取用户的android语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆