4

我是 Android 开发的新手,我有一个问题。

我正在为用户创建通知。没关系。问题是当我更改设备语言时,我的通知不会自己更新。我不知道在 Android 上是否有任何本机方法可以做到这一点。

目前,我的解决方案是:在创建通知时,我创建一个线程来验证语言是否已更改。如果是这样,它会更新我的通知。当用户清除通知时线程停止。

所以,我不知道这是否是一个好的做法,或者是否还有其他原因。

PS:应用程序有很多 strings.xml 文件来翻译字符串。我正在使用 Thread 类来创建线程。

在此先感谢并为糟糕的英语道歉!

4

2 回答 2

0

在您的应用程序类中,您可以保留当前显示的通知 ID 的引用及其信息。您可以在那里检测语言变化onConfigurationChanged(Configuration newConfig)并更新您的通知。

public class App extends Application {
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //update your notifications there is no need for a Thread
    }
}

另一种解决方案(真实的)

为区域设置更改添加接收器

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //retrieve the list of notifications
        //update them (no need for thread)
    }
}

添加到您的清单:

<receiver android:name="MyReceiver">
    <intent-filter>
        <action android:name="android.intent.action.LOCALE_CHANGED">
        </action>
    </intent-filter>
</receiver>
于 2013-10-31T16:47:31.867 回答
0

很可能我不会正确理解您的问题。

由于您有很多 strings.xml 文件来翻译字符串。
您只需要将它们放在适当的文件夹中:

res/values-pt-rPT//葡萄牙葡萄牙
res/values-fr-rFR//法国法国
res/values-fr-rCA//法国法国加拿大

等等。

于 2013-10-31T19:03:32.987 回答