locale信息改变之后,会发广播消息Intent.ACTION_LOCALE_CHANGED,
具体实现在activitymanagerservice.java代码updateConfigurationLocked函数中,
自己写接收代码如下:
接收代码:
public class testReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.v("test", "hello");
if(intent.getAction().compareTo(Intent.ACTION_LOCALE_CHANGED) == 0)
{
//处理
Log.v("test", “received ACTION_LOCALE_CHANGED”);
}
}
}
在AndroidManifest.xml中,添加intent过滤器,声明可以接收广播消息,
如下,
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter>
这样当locale改变之后,onReceive会接收到locale改变的消息,执行相应的处理
转自 http://blog.youkuaiyun.com/liushaogeng/archive/2010/09/28/5912560.aspx
本文介绍如何在Android应用中监听系统Locale的变化。通过注册BroadcastReceiver并使用Intent.ACTION_LOCALE_CHANGED过滤器,开发者可以在Locale发生变化时接收广播并执行相应操作。
1462

被折叠的 条评论
为什么被折叠?



