androidlocalizationandroid-8.0-oreonotification-channel

Android O: Notification Channel localization


I created a Notification Channel like this:

NotificationChannel channel = new NotificationChannel(CHANNEL_ID_FOOBAR, getContext().getString(R.string.notification_channel_foobar), NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);

I provided different translations for R.string.notification_channel_foobar and the channel is created with the language being used at the time of the creation, hence if I eventually change the language of my device, that channel will remain in the old language. Is there a way to overcome this or is this a limitation, i.e. by design?


Solution

  • To apply the new language to your notification channel, you need to listen to the ACTION_LOCALE_CHANGED broadcast in your app and call createNotificationChannel again in your receiver.

    Recreating the channels will update your strings to the new language (none of the other channel features will be modified). You can see it in the documentation.