{"id":746,"date":"2023-02-26T15:53:41","date_gmt":"2023-02-26T07:53:41","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=746"},"modified":"2023-04-29T17:02:18","modified_gmt":"2023-04-29T09:02:18","slug":"android-get-system-language-compatible-with-7","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/android-get-system-language-compatible-with-7\/","title":{"rendered":"Android\u83b7\u53d6\u7cfb\u7edf\u8bed\u8a00(\u517c\u5bb97.0)"},"content":{"rendered":"<p>\u4ece Android 7.0 \u5f00\u59cb\uff0c\u7cfb\u7edf\u8bed\u8a00\u652f\u6301\u591a\u4e2a\uff0c\u53ef\u624b\u52a8\u6392\u5e8f\uff0c\u7cfb\u7edf\u6839\u636e App \u672c\u8eab\u652f\u6301\u7684\u8bed\u8a00\u548c\u624b\u673a\u51fa\u5382\u8bbe\u7f6e\u7684\u8bed\u8a00\u7b49\u56e0\u7d20\u6765\u8c03\u6574 App \u672c\u8eab\u7684\u9ed8\u8ba4\u8bed\u8a00\u3002\u4f7f\u7528 <code>getResources().getConfiguration().getLocales()<\/code> \u8fd4\u56de\u7684\u662f\u4e00\u4e2a LocaleList \u5bf9\u8c61\uff0c\u5b83\u5305\u542b &gt;=1 \u4e2a Locale\uff0c\u5185\u5bb9\u9879\u53ef\u7531\u7528\u6237\u589e\u5220\uff0c\u987a\u5e8f\u53ef\u7531\u7528\u6237\u8c03\u6574\u3002\u4f46\u662f\uff0c\u6b64\u63a5\u53e3\u8fd4\u56de\u7684\u8bed\u8a00\u987a\u5e8f\u548c\u7528\u6237\u5b9a\u4e49\u7684\u987a\u5e8f\u4e0d\u4e00\u5b9a\u4e00\u81f4\uff01<\/p>\n<p><!-- more --><\/p>\n<p>\u83b7\u53d6\u7cfb\u7edf\u771f\u5b9e\u9996\u9009\u8bed\u8a00\uff1a<\/p>\n<pre><code class=\"language-java\">Locale locale;\nif (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {\n    locale = LocaleList.getDefault().get(0);\n} else {\n    locale = Locale.getDefault();\n}\n\nString language = locale.getLanguage() + &quot;-&quot; + locale.getCountry();<\/code><\/pre>\n<pre><code class=\"language-java\">Log.i(&quot;yezhou&quot;, &quot;Language: &quot; + getLanguage() + &quot;, LocaleLanguage: &quot; + getLocaleLanguage() + &quot;, Country: &quot; + getCountry());\n\/\/Language: zh, LocaleLanguage: zh-CN, Country: CN\n\npublic static String getLanguage() {\n    Locale locale;\n    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {\n        locale = LocaleList.getDefault().get(0);\n    } else {\n        locale = Locale.getDefault();\n    }\n    return locale.getLanguage();\n}\n\npublic static String getLocaleLanguage() {\n    Locale locale;\n    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {\n        locale = LocaleList.getDefault().get(0);\n    } else {\n        locale = Locale.getDefault();\n    }\n    return locale.getLanguage() + &quot;-&quot; + locale.getCountry();\n}\n\npublic static String getCountry() {\n    Locale locale;\n    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {\n        locale = LocaleList.getDefault().get(0);\n    } else {\n        locale = Locale.getDefault();\n    }\n    return locale.getCountry();\n}<\/code><\/pre>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/developer.android.com\/reference\/java\/util\/Locale.html\">https:\/\/developer.android.com\/reference\/java\/util\/Locale.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece Android 7.0 \u5f00\u59cb\uff0c\u7cfb\u7edf\u8bed\u8a00\u652f\u6301\u591a\u4e2a\uff0c\u53ef\u624b\u52a8\u6392\u5e8f\uff0c\u7cfb\u7edf\u6839\u636e App \u672c\u8eab\u652f\u6301\u7684\u8bed\u8a00\u548c\u624b\u673a\u51fa\u5382\u8bbe\u7f6e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-746","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=746"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/746\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}