Add meta-data support inside Android receiver components#132
Open
PrestaEdit wants to merge 1 commit into
Open
Conversation
Allows plugins to declare <meta-data> elements inside <receiver> blocks via nativephp.json, enabling use cases such as AppWidgetProvider which requires a meta-data pointing to the widget info XML resource. Applies the same pattern already used in buildServiceEntry(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
buildReceiverEntry()method did not supportmeta-dataelements inside receiver components, unlikebuildServiceEntry()which already callsbuildComponentMetaData().This made it impossible to register an Android
AppWidgetProvidervia a plugin'snativephp.json, because Android requires a<meta-data android:name="android.appwidget.provider" android:resource="@xml/..."/>element inside the<receiver>block to recognize it as a widget provider and display it in the widget picker.Without this, the receiver is registered (intent-filter is present) but Android silently ignores it as a widget provider — the widget never appears in the picker.
Solution
Apply the same pattern already used in
buildServiceEntry(): readmeta_data/meta-datafrom the receiver config and pass it to the existingbuildComponentMetaData()method (which already handles bothvalueandresourceattributes).Usage example
nativephp.jsonin a plugin:{ "android": { "receivers": [ { "name": "com.example.myplugin.MyWidgetProvider", "exported": true, "intent-filters": [ { "action": "android.appwidget.action.APPWIDGET_UPDATE" } ], "meta-data": [ { "name": "android.appwidget.provider", "resource": "@xml/my_widget_info" } ] } ] } }Produces:
Test plan
it_adds_meta_data_with_resource_inside_receiver— resource attribute (AppWidgetProvider use-case)it_adds_meta_data_with_value_inside_receiver— value attributeit_supports_both_intent_filters_and_meta_data_in_receiver— combined intent-filter + meta-datait_keeps_receiver_self_closing_without_nested_content— no regression on receivers without nested content🤖 Generated with Claude Code