Skip to content

Add meta-data support inside Android receiver components#132

Merged
simonhamp merged 1 commit into
NativePHP:mainfrom
PrestaEdit:feat/receiver-meta-data
May 19, 2026
Merged

Add meta-data support inside Android receiver components#132
simonhamp merged 1 commit into
NativePHP:mainfrom
PrestaEdit:feat/receiver-meta-data

Conversation

@PrestaEdit
Copy link
Copy Markdown
Contributor

Problem

The buildReceiverEntry() method did not support meta-data elements inside receiver components, unlike buildServiceEntry() which already calls buildComponentMetaData().

This made it impossible to register an Android AppWidgetProvider via a plugin's nativephp.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(): read meta_data/meta-data from the receiver config and pass it to the existing buildComponentMetaData() method (which already handles both value and resource attributes).

Usage example

nativephp.json in 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:

<receiver
    android:name="com.example.myplugin.MyWidgetProvider"
    android:exported="true">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data android:name="android.appwidget.provider" android:resource="@xml/my_widget_info" />
</receiver>

Test plan

  • it_adds_meta_data_with_resource_inside_receiver — resource attribute (AppWidgetProvider use-case)
  • it_adds_meta_data_with_value_inside_receiver — value attribute
  • it_supports_both_intent_filters_and_meta_data_in_receiver — combined intent-filter + meta-data
  • it_keeps_receiver_self_closing_without_nested_content — no regression on receivers without nested content

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks

@simonhamp simonhamp merged commit c716c78 into NativePHP:main May 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants