Search code examples
androidwidgetbroadcastreceiverlabelandroid-widget

Using a string resource to name (label) a widget's BroadcastReceiver


I've a widget defined as follows:

[BroadcastReceiver(Label = "Upcoming")]
[IntentFilter(new string[] { "android.appwidget.action.APPWIDGET_UPDATE" })]
[MetaData("android.appwidget.provider", Resource = "@xml/widget_daily")]
public class Widget_Daily : AppWidgetProvider
{
...
}

What I'm after is to localise the "Label" associated with the BroadcastReceiver, referencing the Resource.String.widget_title_upcoming string resource.

As a side-question, once this is managed, what happens to a user's Upcoming widget if 1) they already had it on their home screen and 2) its Label has been changed as their phone's language is set to a supported non-English language. Will it continue to operate as before? Or does it need to be re-inserted for it to function correctly?


Solution

  • This should work:

    [BroadcastReceiver(Label = "@string/Upcoming")]