【问题标题】:Android Settings LocalePicker on HoneycombHoneycomb 上的 Android 设置 LocalePicker
【发布时间】:2011-09-29 23:45:02
【问题描述】:

我正在实现一个使用本地语言设置的应用程序,可以从以下位置访问: 菜单 > 设置 > 语言和键盘 > 选择语言 > 区域设置

我还可以使用以下代码列出语言的意图直接打开区域设置页面:

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

^-- 代码来源:Change language settings (locale) for the device

这适用于 Honeycomb 之前的版本。然而 Honeycomb 的设置在左侧有一个小的导航区域,如下所示:

当我执行上面的代码时,我得到了这个错误:

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?

知道为什么会这样吗?如果我将“com.android.settings.LocalePicker”更改为“com.android.settings.Settings”,它将打开设置页面到您上次选择的任何设置,但如果我尝试将类名更改为:“com .android.settings.Settings.LocalePicker”它又炸了。这是我在解决此问题之前使用的一些修改后的代码:

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);

运行根据版本号执行不同操作的代码并不理想,所以如果有人知道如何解决这个问题,我将不胜感激。

谢谢!

【问题讨论】:

  • 另外,一个单独的问题(我可能会作为一个新问题发布)是否有人知道如何安装新语言或者它是否是固件的一部分并且只能通过黑客或使用修改来更改固件?

标签: android settings locale multilingual android-3.0-honeycomb


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多