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
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. However the settings for Honeycomb has the little navigation area off to the left, like so:
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开发者_JAVA技巧.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. 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);
精彩评论