简体   繁体   English

Android 在 Honeycomb 上设置 LocalePicker

[英]Android Settings LocalePicker on Honeycomb

I am implementing an app that uses the native language settings which can be accessed from: Menu > Settings > Language & Keyboard > Select Language > Locale我正在实现一个使用本地语言设置的应用程序,可以从以下位置访问:菜单 > 设置 > 语言和键盘 > Select 语言 > 区域设置

I can also open the Locale page directly using an intent which lists the languages by using the following code:我还可以使用以下代码直接使用列出语言的意图打开区域设置页面:

Intent languageIntent = new Intent(Intent.ACTION_MAIN);
languageIntent.setClassName("com.android.settings", "com.android.settings.LocalePicker");
activity.startActivity(languageIntent);

^-- code credit: Change language settings (locale) for the device ^-- 代码来源: 更改设备的语言设置(区域设置)

This works great on versions before Honeycomb.这适用于 Honeycomb 之前的版本。 However the settings for Honeycomb has the little navigation area off to the left, like so:然而 Honeycomb 的设置在左侧有一个小的导航区域,如下所示:

图片

and when i execute the above code I get this error:当我执行上面的代码时,我得到了这个错误:

Starting: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.LocalePicker } from pid 24294
FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/com.android.settings.LocalePicker}; have you declared this activity in your AndroidManifest.xml?

Any idea why this is happening?知道为什么会这样吗? If i change "com.android.settings.LocalePicker" to "com.android.settings.Settings" it will open up the settings page to whatever setting you had last selected but if i try to change the classname to something like: "com.android.settings.Settings.LocalePicker" it blows up again.如果我将“com.android.settings.LocalePicker”更改为“com.android.settings.Settings”,它将打开设置页面到您上次选择的任何设置,但如果我尝试将类名更改为类似:“com .android.settings.Settings.LocalePicker”它又炸了。 Here is some modified code which I'm using until this issue is resolved:这是我在解决此问题之前使用的一些修改后的代码:

Intent languageIntent = new Intent(Intent.ACTION_MAIN);
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
final int HONEYCOMB = 11;
if (currentApiVersion < HONEYCOMB) // "HONEYCOMB" should be replaced with android.os.Build.VERSION_CODES.HONEYCOMB, but version code 'honeycomb' is not supported...
{
    languageIntent.setClassName("com.android.settings", "com.android.settings.LocalePicker");
}
else
{
    languageIntent.setClassName("com.android.settings", "com.android.settings.Settings");
}
activity.startActivityForResult(languageIntent, WtgActivity.LANGUAGE_CHANGE_REQUEST);

Running code that does something different based on version number is not ideal, so if anyone knows how to fix this i would appreciate it.运行根据版本号执行不同操作的代码并不理想,所以如果有人知道如何解决这个问题,我将不胜感激。

Thanks!谢谢!

Try this:尝试这个:

Intent languageIntent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
startActivity(languageIntent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM