Android如何接收locale改变的消息

    技术2025-09-15  64

    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.csdn.net/liushaogeng/archive/2010/09/28/5912560.aspx

    最新回复(0)